Task.wait being super inconsistent locally

Soo i was making a dash system but it seems like the diffrences in distance between me and my friend is huge and what i found out is that task.wait is not consistent between computers and is not consistent in the same computer either when ran locally

i checked it by doing this `while true do

local old = time()
task.wait(0.00001)
print(time()-old)

end` is there a way to balance the timing out?

2 Likes

The inconsistency in task.wait is a known issue. If consistency is key, I would recommend using a different method.

Some examples might be:

  • Use Heartbeat Event: Instead of relying on task.wait, you can use the RunService.Heartbeat event, which fires every frame.
  • Fixed Time Step: A fixed time step loop using RunService.Heartbeat to ensure consistent updates regardless of frame rate.
  • Debounce/Rate Limit: A debounce function or rate limiter to ensure that your dash function isn’t called too frequently, which can cause inconsistencies.
  • Time Delta Calculation: Use delta time calculations to adjust the movement based on the elapsed time since the last frame.

You can achieve more consistent and reliable timing for your dash system using an approach like this:

local RunService = game:GetService("RunService")

local function dash()
    -- Your dash logic here
end

local lastTime = 0
local dashInterval = 0.1 -- Desired dash interval in seconds

RunService.Heartbeat:Connect(function(deltaTime)
    lastTime = lastTime + deltaTime
    if lastTime >= dashInterval then
        dash()
        lastTime = 0
    end
end)
1 Like

Task.wait() and everything in roblox runs at 60 frames per second, this mean you can’t do this small timestampt from what i know

task.wait(1/60) -- most precise waiting in roblox
1 Like

Is there a way to do it without the event because it’s gonna make the code really messy and annoying to work with

1 Like

Not really. Technically you’re still using the event, but if you’re referring to needing a one-liner, you could try RunService.Heartbeat:Wait().

You can condense it into a function that you can call:

local RunService = game:GetService("RunService")

local function dash()
    -- Your dash logic here
end

local function yield(length)
   local running = coroutine.running()
   local start = 0
   local connection; connection = RunService.Heartbeat:Connect(function(dt)
        if start >= length then
            coroutine.resume(running) -- continue the thread 
            connection:Disconnect()
            return
        end
        start += dt
   end)

   coroutine.yield() -- pause the thread
   return start
end

yield(1) -- wait for 1 second
dash()

But your problem here is distance, right? How exactly are you handling the dash functionality?

well its a while loop that runs while the BodyVelocity exists and so i have a x value and a math function (-2x+100) the x runs until it reaches around 30 the reason its not a for loop is because the dash can also hit and when it hits iwant it to stop and do a diffrent action

1 Like