Hello! I am wondering if anyone knows how to make a Leaderstats script with Max Stats. So like the max value is 9999 For coins, and such. This is my current Script, but I want a Max value so it doesn’t bug out. Any help will be appreciated!
Value.Changed:Connect(function(value) -- Watch for changes in the NumberValue.
if value > 9999 then -- if the "value" of the NumberValue > 9999, then set the NumberValue value to 9999.
value.Value = 9999
end
end)
You’ll have to connect the .Changed to each of the numbervalues. For example,
That will work for the first time, but You’ll need to watch the value every time it changes, for this to work. You will need to include in the script, like so:
eggsopened.Changed:Connect(function(value)
if value > 9999 then -- if the "value" of the NumberValue > 9999, then set the NumberValue value to 9999.
eggsopened.Value = 9999
end
end)
Include it after the variables are set/parented.
local eggsopened = Instance.new("IntValue")
eggsopened.Name = "EggsOpened"
eggsopened.Value = 0
eggsopened.Parent = stats
eggsopened.Changed:Connect(function(value)
if value > 9999 then -- if the "value" of the NumberValue > 9999, then set the NumberValue value to 9999.
eggsopened.Value = 9999
end
end)
I assume your issue isn’t that you necessarily want a max, but you just don’t want there to be too many characters on the leaderboard.
Instead of using a IntValue, use a StringValue. Then in your script that sets this value, it’s possible to output values like 10k, or 1.2m with some code.
If you truly want a max value, this is something that should be checked before increasing the value. You should never be using these values as your actual data. You should be storing it somewhere (like in a variable in some table for example.)
Then, when it’s time to increase the value:
// some code before...
playerMoney=math.min(playerMoney+AMOUNT, 99999)
money.Value = playerMoney
// more code below...
For some reason at a super high number, the Leaderstats bug out and turn it back to 0, which is why I am trying to find this. It already does 1M and all of that on the leaderboard.
How do you plan on increasing the value? This should be your question. Once you know how you plan on increasing the value, then come back to the solution I provided.
Include it after the variables are set/parented. The changed event allows you to tell whenever the variable changes, then cap it if it is greater than the max value (in this example, 9999)
local eggsopened = Instance.new("IntValue")
eggsopened.Name = "EggsOpened"
eggsopened.Value = 0
eggsopened.Parent = stats
eggsopened.Changed:Connect(function(value)
if value > 9999 then -- if the "value" of the NumberValue > 9999, then set the NumberValue value to 9999.
eggsopened.Value = 9999
end
end)