While true do loop speeds up

I would not recommend to use a while wait loop, mainly because they are not guaranteed to fire when you want them to, more information can be found here.

You can use heartbeat instead and check to see if 3 seconds have passed since the last update.

local RunService = game:GetService("RunService")
local NextStep = tick()


RunService.Heartbeat:Connect(function()
	if tick() >= NextStep then
		NextStep = NextStep + 3
		-- Code
	end
end)

And @XxELECTROFUSIONxX, where did you see that tick() is going to be deprecated?

1 Like