In the shop when you buy something, if you dont have enough money instead of stopping you the leaderstat amount will go below zero, how do I stop this?
✓ ANSWER ACCEPTED
How do I make leaderstats not go below zero?
1 answer
✓ Accepted answer
Im assuming for your script you did something a little like this
script.Parent.MouseButton1Click:Connect(function(player)
player.leaderstats.stat.Value -= 30 -- 30 is just a placeholder value
-- whatever the code is for when its bought
end)
Instead you should do
script.Parent.MouseButton1Click:Connect(function(player)
if player.leaderstats.stat.Value >= 30 then -- ">=" means greater than, or equal to
player.leaderstats.stat.Value -= 30
-- put whatever code you want to activate when the item is bought
end
end)
1 comment
0
I would use math.max, but yours work too -- https://developer.roblox.com/en-us/api-reference/lua-docs/math
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Can you show us the script?