Is there a wait() function like there is in LuaU?

Dude moving from Roblox here, is there a similar function to wait()? Never coded in actual Lua, only the Roblox version of Lua, LuaU.

Also, probably a dumb question, but how do I use a while true loop without it freezing the game? You could just put a wait() in the while loop in Roblox to stop it from crashing, but is there a way to do it here?

you can use Update func

function update(self, dt)
    print("update",dt)
end

or timer

timer.delay(1,true, function() print("timer every second")end)

or flow

flow.start(function()
      while true do
           flow.delay(self.delay)
      end
end)

or coroutines

I had a couple of strange issues with the built-in coroutines mentioned in the above post. So to add to the available options, I’ve not had any issues using DefUniCo.

    self.start_coroutine(function(self)
        -- wait one second
        wait_seconds(1)

        print("One second has passed.")
    end)

A reminder that the Lua runtime is single threaded.
A coroutine aren’t run on a separate thread, so when you wait X seconds, you’re stalling the entire engine.

3 Likes