Hey Developers,
So I wrapped a while true do loop in a corountine so I could add scripts after it and to improve speed, I’m doing this, however it’s not working. My Hi isn’t printing nor is the timer. I get no errors, here is my script:
coroutine.wrap(function()
while true do
print('hi')
for i = StartTime, 1, -1 do
print(i)
wait(1)
end
wait()
end
end)
Well, there’s nothing wrong with the code. It’s just that you’re not running the function. You have to first create the function stored inside of a variable and then call that variable. It’s like creating a regular function but not running it.
I would take a look at the coroutine.wrap section here to learn more.
local func = coroutine.wrap(function()
while true do
print('hi')
for i = 10, 1, -1 do
print(i)
wait(1)
end
wait()
end
end)
func() -- run the function