Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

4 comments

0

Is this a localscript?

0

Also can you show the whole script?

0

Its not a localScript

0

And thats the whole script

2 answers

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!

2 comments

0

@JBennetChief9 - Now it just shows "bought"

0

Was I also meant to show you how to put it in your Inventory?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.