I am trying to make a vending machine so when you click it you get a bloxy cola. but when i click it i get "not enough money" in the output even if i have 100 Schoolbux. (it's in a normal script)
Here is my code:
script.Parent.ClickDetector.MouseClick:Connect(function(plr) if plr:WaitForChild("leaderstats").Schoolbux.Value >= 5 then print("bought") else print("not enough money") end end)
Try this:
script.Parent.MouseClick:Connect(function(plr) local leaderstats = plr:FindFirstChild("leaderstats") if leaderstats then --Checks to see leaderstats exists if leaderstats.Schoolbux.Value == 5 or leaderstats.Schoolbux.Value >= 5 then print("Bought Successfully!") else print("Not enough cash!") end else print(plr.Name.."'s leaderstats were not found!") end end)
Give me a message if this doesn't work!
Let's raise some questions first.
Is this a localscript? No, it isn't. LocalScripts can't operate in the Workspace unless parented to a rig associated with a player (basically the player's Character).
Number 2: Why is the value Schoolbux
static, and why aren't you checking the value by using print()
? Consider these when you're scripting.
Okay, so in order to check your value you just print it:
print(player.leaderstats.Schoolbux.Value)
By doing this the output will give you the number representing the value. If that number is < 5, the script will not go any further than telling you that you have insufficient funds.