Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Time.deltaTime for Roblox Lua?

1 answer

✓ Accepted answer

While you can only calculate the per-renderframe delta time on the Client (because only LocalScripts can use RenderStepped), you can implement delta time using tick():

local last = tick()
while true do
	local t = tick()
	local dt = t - last
	last = t

	print(tick)
	print(dt)
	
	wait() --waits 1/30th of a second, usually.
	--game:GetService("RunService").RenderStepped:wait() --waits the exact amount of time it takes to create the next frame. Maxes at 1/60th of a second.
end

EDIT: For future explorers:

game:GetService("RunService").Heartbeat:wait() updates with the physics handling on the Server, which is slightly faster than what wait() on its own will give you.

1 comment

0

Thanks a lot :)

This discussion is preserved as it was. New answers, comments, and votes are closed.