This is an easy way to get started with shop scripts. This will go over everything you need to know to get a money system working. Before you start this I suggest reading Basic Scripting.
Below is a basic leaderboard script. For now, I'm going to access everything using the name "Cash", so if you change the name of your money (cash.Name = "Cash") in the leaderboard to something like "Credits", remember to change the script(s) to reflect this change.
Another important change you will have to make here is to make sure your Cash leaderboard starts your character off with some money (For example, cash.Value = 10000000).
print("Cash Leaderboard Loaded") function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Value = 1000 cash.Parent = stats stats.Parent = newPlayer end game.Players.ChildAdded:connect(onPlayerEntered)
Basic onTouch Money Checker
This will be used for pretty much anything that you only want to happen to people if they have enough cash. So, the basic frame work of everything onTouch will start us off.
function onTouched(hit) end script.Parent.Touched:connect(onTouched)
Now, lets add an 'if' line to make sure its a human!
if hit.Parent.Humanoid~= nil then
With every 'if' line you need another end, so we will count those up a little later. Now, we need to define where the money is.
We only want this to work if the player has enough cash:
if cash.Value>= 100 then
Then to take away the money! Notice, we will need to have a starting value of some money in order to make this script work:
cash.Value= cash.Value - 100
Lets look at what we have so far:
function onTouched(hit) if hit.Parent.Humanoid~= nil then cash = game.Players:findFirstChild(hit.Parent.Name).leaderstats.Cash -- Find out who touched. if cash.Value >= 100 then cash.Value = cash.Value- 100 --What you want to happen goes here. end end end script.Parent.Touched:connect(onTouched)
What does that do? It will check and make sure what is hitting it is a human. Then, it will check to make sure it has enough cash. Finally, it will take away that cash. You can pretty much choose what you want to happen after that, imagination is key!