Hi, i want something to execute every frame at 60 fps in a localscript.
But now that roblox allows players to increase their frame rate, the game will begin to do things much faster.
How do i fix this?
task.wait()
Hi, i want something to execute every frame at 60 fps in a localscript.
But now that roblox allows players to increase their frame rate, the game will begin to do things much faster.
How do i fix this?
task.wait()
I found a solution!
local running = true
local RunService = game:GetService("RunService")
local targetDelta = 1 / 60
local accumulatedTime = 0
local connection
connection = RunService.Heartbeat:Connect(function(deltaTime)
if not running then
connection:Disconnect()
return
end
accumulatedTime = accumulatedTime + deltaTime
if accumulatedTime >= targetDelta then
accumulatedTime = accumulatedTime - targetDelta
end
end)