Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] How to make function repeat every 10 seconds without stopping the whole script?

Hey guys, as in the title. You know, you can do

while true do
  --Script here
    wait(10)
end

but that will stop the whole script, or in other words, it would get stuck in there and repeat into an infinity AND BEYOND! But I need it to be looping infinitely "in the background" so the script can continue its way down but the infinite loop will be there. I hope you get it :D

I did some research, but didn't really help - I found something with WaitForAll, but I want to understand my scripts. Also, try to explain a bit (sentence above).

Thanks in advance!

1 comment

0

If you any have one infinite loop I would just put it at the bottom of your script.

2 answers

✓ Accepted answer

you can use spawn() or coroutines.

spawn(function()
	while true do
		print("john")
		wait(1)
	end
end)

local foo = coroutine.wrap(function()
	while true do
		print("hello john!")
		wait(1)
	end
end)

foo()

2 comments

0

I will user the Spawn() ! Thanks mate!

0

I guess I can use spawn(MyFunction), right?

This discussion is preserved as it was. New answers, comments, and votes are closed.