Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Trying to make a vending machine --- if money.Value >= 5 then doesnt work?

Asked by 4 years ago

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)
0
Is this a localscript? Gabe_elvin1226aclan 323 — 4y
0
Also can you show the whole script? Gabe_elvin1226aclan 323 — 4y
0
Its not a localScript Recrucity 13 — 4y
0
And thats the whole script Recrucity 13 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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!

0
@JBennetChief9 - Now it just shows "bought" Recrucity 13 — 4y
0
Was I also meant to show you how to put it in your Inventory? JB_SuperGamer 165 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

Answer this question