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

Anyone know how to limit leaderstat like in the game bee swarm sim. backpack storage?

Asked by 6 years ago

When i destroy i blocks i gain 10 points out of 150 (10/150) when reached 150 then it will stop adding in the leaderstat, anyone know how to this? i will make a multiplayer game like that lol hope you understand what i thinking haha, here is my code i use but nothing happens lol please help thanks!

Player = game:GetService("Player").LocalPlayer

money = Player.leaderstats.Money.Value

while true do
    wait(1)
    if money.Value >= 150 then
        money.Value = 150
    end
end)
0
That's not very efficient, you should use money.Changed instead of a while true do brokenVectors 525 — 6y

2 answers

Log in to vote
1
Answered by
otto045 41
6 years ago

Hello, there were a few problems with your code. I have made some changes

game.Players.PlayerAdded:connect(function(player) -- Runs the script when player has joined the game (Before there was no trigger)
local Player = player.Name -- Getting the players name

money = game.Players[Player].leaderstats.Money -- Removed the .Value as it allready appears down below when changing

while true do
    wait(1)
    if money.Value > 150 then -- Made it so it is only if it is greater (Just so it would not create an infinite loop)
        money.Value = 150
    end
end
end)

If you need any more help with it just tell me :)

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

Hi!

if i where you i would just do if the property changed

Player = game:GetService("Player").LocalPlayer

    money = Player.leaderstats.Money.Value

money:GetPropertyChangedSignal("Value"):Connect(function() -- This means everytime the property called "Value" changed it will execute the function.
    if money.Value >= 150 then
        money.Value = 150
    end
end)

But what you can also do is when you add the money to the player you check if the money is greater or equal than 150 if it is then just return the function.

Property Chagned signal here.

Answer this question