right now i just have my timer in the render step function doing timer -= 1 every frame.
But i want to compensate for lag, i know that deltaTime does that but i dont know how to use it correctly. Can someone please explain how i would use deltaTime here?
1 Like
AFAIK, mathematically (though not really important), DeltaTime is just the time passed since something.
In this context, you would use Heartbeat (an event that fires every frame) and use the deltaTime it returns, which is the time since the last Heartbeat call.
Heartbeat is an event stored in RunService.
Example of a proper time using Heartbeat:
local RunService = game:GetService("RunService")
local TextLabel = ...
local TimePassed = 0
RunService.Heartbeat:Connect(function(deltaTime)
--// Runs every frame
TimePassed += deltaTime
--// TimePassed plus time since last heartbeat
TextLabel.Text = math.round(TimePassed)
end)
3 Likes