I have a leader stat value Called “Points” but i don’t know how i can max the value for example I want to max the value of points to 5 so you cant get anymore points then 5.
You use Value.Changed to see whenever the points value changes, then see if it’s greater than 5. If it is, then set it to 5.
points.Changed:Connect(function(value)
if value > 5 then
points.Value = 5
end
end)
Or, you can use math.clamp.
math.clamp(points.Value, 0, 5)
Basically, if the points value is out of the specified bounds, then it will clamp it to the closest value. -1 will turn into 0. And 6 will turn into 5.
3 Likes
You can listen for the Changed event
points.Changed:Connect(function(new)
points.Value = math.clamp(new, 0, 5)
end)
math.clamp will constrain a number between two values, so if the new amount of points is smaller than 0 then it will be forced back up to 0 but if it goes greater than 5 then it will be forced down to 5. There is a chance that the event can fire twice for the latter case, but in this situation it doesn’t matter
1 Like
Its working thanks! I was researching for so long