Why does this produce different results?

Aren’t these both looping every 0.1 of a second? The RenderStepped loop decreases my fps a lot, while the other one doesn’t.

local frame = 0

game:GetService("RunService").RenderStepped:Connect(function()
	frame = frame + 1
	if frame == 6 then
		frame = 0
		for i = 1, 100 do
			print(i)
		end
	end
end)

while wait(0.1) do
	for i = 1, 100 do
		print(i)
	end
end

I checked with tick() and they both are looping at approximately 0.1 of a second, so why then does the RenderStepped loop decrease performance so much?

They both fire approximately every 0.1 seconds.

1 Like

just realised how stupid my reply was, ignore me :slight_smile:

1 Like

Happens to the best of us :joy:

1 Like

Related reading: RunService.Heartbeat switching to variable frequency

Also a good post by @buildthomas on the same thread: RunService.Heartbeat switching to variable frequency - #14 by buildthomas

2 Likes

Thanks!