Ad
Log in to vote
1

How do I make leaderstats not go below zero?

Asked by 16 days 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 — 16d

1 answer

Log in to vote
0
Answered by 16 days ago
Edited 16 days 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 3088 — 15d
Ad

Answer this question