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

How do I make leaderstats not go below zero?

Asked by 1 year ago

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?

0
Can you show us the script? guuguu058 9 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)
0
I would use math.max, but yours work too -- https://developer.roblox.com/en-us/api-reference/lua-docs/math Leamir 3138 — 1y
Ad

Answer this question