Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a strength cap on a leaderstat?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)
0
For some reason it doesn't stop them from going over it. MemeSnakex -3 — 7y
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. KidTech101 376 — 7y
0
Thanks it works. MemeSnakex -3 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
while true do
    if player.leaderstats.strength.Value > 1000000000 then
    player.leaderstats.strength.Value = 1000000000
    wait(1)
end
0
Thats greater than. raspyjessie 117 — 7y
0
Yes, so if the value goes higher than 1 bil it is put back to 1 bil. Citranix 19 — 7y
0
I've also tried this one but every time I press play to test it, it crashes the game. MemeSnakex -3 — 7y
0
Are you sure? Did you use the 'wait(1)' Citranix 19 — 7y

Answer this question