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:
1 | script.Parent.ClickDetector.MouseClick:Connect( function (plr) |
2 | if plr:WaitForChild( "leaderstats" ).Schoolbux.Value > = 5 then |
3 | print ( "bought" ) |
4 | else |
5 | print ( "not enough money" ) |
6 | end |
7 | end ) |
Try this:
01 | script.Parent.MouseClick:Connect( function (plr) |
02 | local leaderstats = plr:FindFirstChild( "leaderstats" ) |
03 | if leaderstats then --Checks to see leaderstats exists |
04 | if leaderstats.Schoolbux.Value = = 5 or leaderstats.Schoolbux.Value > = 5 then |
05 | print ( "Bought Successfully!" ) |
06 | else |
07 | print ( "Not enough cash!" ) |
08 | end |
09 | else |
10 | print (plr.Name.. "'s leaderstats were not found!" ) |
11 | end |
12 | 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:
1 | 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.