I have a tycoon button that when pressed, takes away the amount that is specified in a value. The problem is that if I step on the button and I don't have enough money, it won't work when I do.
local cost = script.Parent.cost
game.Players.PlayerAdded:Connect(function(player)
local debounce = true
script.Parent.Touched:Connect(function()
local plrstats = player.leaderstats.Money
if debounce then
debounce = false
if plrstats.Value >= cost.Value then
plrstats.Value = plrstats.Value - cost.Value
wait(10)
debounce = true
end
end
end)
end)
This is a representation of the model:
button
basepoint
buyscript (the script above)
cost (number value)
stand (just a part below the basepoint for design)
The Lua code above is not a script or line of code, just a recreation of the model in the explorer.
The script is made to work so that when a player touches the button, it finds the value of "cost" (the price for say, a wall of a tycoon) and if the player has more or equal to the desired amount, take the money away. The debounce is obviously just the cooldown for the button.
