RenderStepped every 2 frames?

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:

image

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.

1 Like

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)
7 Likes

A post was merged into an existing topic: Off-topic and bump posts