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)
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)
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