while true do
wait()
doStuff()
end
This will give you every other frame.
while true do
wait()
doStuff()
end
This will give you every other frame.
Wouldn’t wait always do 1/30th of a second, no matter the fps? If you use a wait() loop, wouldn’t it only be every 2 frames if the user has a solid 60 fps?
No, all the timing is in the frames. See this picture:
A loop yielding using wait() would run exactly once every two frames.
Ah, alright.
This is actually correct, wait yields for a fixed period.
My diagram is just an approximation at 60 fps.
There’s been a few good solutions here, but I wanted to share a variation of OP’s solution using a simple boolean variable.
local x = false
RunService.RenderStepped:connect(function()
x = not x
if x then
-- code
end
end)