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

How exactly would I make this loop not speed up and break?

Asked by 7 years ago
Edited 7 years ago

I am trying to make a cash script, for every minute you get 10 cash but the problem is I tried something like this ;

game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "leaderstats"
local val = Instance.new("NumberValue", folder)
val.Name = "Cash"
while true do
    wait(60)
    val.Value = val.Value + 10
end
end)

(if the above script doesn't work, I just wrote it quickly (on iPhone), it's just an example of my real code)

The problem with this is that it increases the speed of the loop every time a player joins the game, such as if I had a variable "i = 1" and put "i = i + 1" inside the loop it would go faster and faster everytime a player joined.

I don't know how to bypass this, by the way FilterningEnabled is ON.

0
What do you mean by it would go faster & faster every time a player joins? :P TheeDeathCaster 2368 — 7y
0
Apparently every time a player joins a new loop starts, since I don't have a loop for a specific player. UnleashedGamers 257 — 7y
0
Obviously your issue is that you put the while true do loop inside of the playerAdded event. RubenKan 3615 — 7y

Answer this question