Making a game that requires high numbers, how could I make a StringValue not turn negative as a leaderstat?
(Assuming you converted your stringvalue to an intvalue,)
You could use
intValue.Changed:Connect(function(val) intValue.Value = math.abs(val) == val and val or 0 end)
However, you should always check if it is negative before assigning a value to the stat.
Hope this helps!
First off, I believe a StringValue
can NOT go negative unless you do
lua
local Number = tonumber('-1')
But:
If it was a intvalue you can used .Changed
event to detect change and if it goes below 0 then change it back to 0:
local IntValue = Instance.new('IntValue') IntValue.Value = 0 IntValue.Changed:Connect(function() if IntValue.Value < 0 then IntValue.Value = 0 end end)
This will prevent the value going below 0. Hopefully, this helped. Good luck!
Whenever you update the stat, you can use math.clamp to clamp the value between a minimum and a maximum. Example:
local currentStat = 0 local intvalue = workspace.IntValue function updateStat(stat) local newStat = math.clamp(stat, 0, 9999999999) intvalue.Value = newStat end while true do wait(1) updateStat(currentStat + 1) end