Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a strength cap on a leaderstat?

So I've been trying to do it myself, but I'm not that good at scripting just yet. I was wondering how you put a strength cap in a leaderstat, so I want the cap to be 1 Billion. But I'm not sure how to do it.

2 answers

✓ Accepted answer

Try something like:

-- if the strength of the player is less than or equal to 999,999,999
if(player.leaderstats.strength <= 999999999)then
	-- add 1 to their strength (1,000,000,000)
	player.leaderstats.strength = player.leaderstats.strength + 1;
else
	-- if this is the path the script takes, the player's strength is at least 1,000,000,000
end

Edit: Try:

player.leaderstats.strength.Changed:connect(function(newvalue)
	-- whenever the value is changed, clamp it between 0 and 10^9;
	player.leaderstats.strength.Value = math.clamp(newvalue, 0, 1000000000);
	wait();
end)

3 comments

0

For some reason it doesn't stop them from going over it.

0

Are you adding to the player's strength anywhere outside of the if statement? If you do, the new value won't be checked. Will edit with a more "universal" fix.

0

Thanks it works.

while true do
	if player.leaderstats.strength.Value > 1000000000 then
	player.leaderstats.strength.Value = 1000000000
	wait(1)
end

4 comments

0

Thats greater than.

0

Yes, so if the value goes higher than 1 bil it is put back to 1 bil.

0

I've also tried this one but every time I press play to test it, it crashes the game.

0

Are you sure? Did you use the 'wait(1)'

This discussion is preserved as it was. New answers, comments, and votes are closed.