How do I change num inside while task.wait(num) do?

local num = workspace.Number.Value -- 1 second
while task.wait(num) do
	print("hi")
end

lets say that I changed the num value using other script (for ex.: player touched a part and the num increased by 1), and inside the while loop it hadnt changed, still at 1 print per second.

1 Like

Using a variables stores the value of it at the particular instant, so even if you change the value the ‘num’ variable will still be equal to 1. To fix this, simply wait the num value instead of the variable

while task.wait(workspace.Number.Value) do
	print("hi")
end

So it will wait the updated value if you change it

1 Like

oh, it actually was this easy to solve. thanks for helping me out!

Yeah lol so this a learning experience for both of us :smiley:

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