Why isnt this while true do work?

Im trying to make a game that you earn a currency every minute. And im using a datastore that i found from a plugin, this way everything it saves are child of a script in ServerScriptService. I put the currency in it as a NumberValue and put a script in it. But whenever i try to make it work it just adds it only once and not always

while true do
script.Parent.Value = script.Parent.Value + 100
wait(60)
end

I tried using smaller numbers like 5 and it always stays at 100.

Can you try adding a print(), before, inside and after the loop?

print("Loop starting")
while true do
print("Looping")
script.Parent.Value = script.Parent.Value + 100
wait(60)
end
print("Loop finished")

I edited wait to 3 and the output is like this

  20:46:22.747  Loop Starting  -  Server - tokensc:1
  20:46:22.747  Loop Started  -  Server - tokensc:4
  20:46:26.443   ▶ Loop Started (x17)  -  Server - tokensc:4

Loop started increases every 3 seconds

I think it could be cause of the script being in game.Players.Player.Stats.Tokens.Script

ill change the place.

Putting the script in StarterPack solved the issue.
Heres the code i used for future problems anybody will have

while true do
	script.Parent.Parent.Stats.Tokens.Value = script.Parent.Parent.Stats.Tokens.Value + 100
	wait(3)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.