Is delta time the same across all clients and the server?

Let’s say I was making a tower defense game, and wanted to move enemies along a path, there can be several on the screen at the same time, and they are moved every fram with a function called MoveEnemies(deltaTime), with the delta time parameter so they move at a constant speed, my question is if I could do something like this on the server

while true do
    local dt = RunService.Heartbeat:Wait() + RunService.Heartbeat:Wait() + RunService.Heartbeat:Wait() + RunService.Heartbeat:Wait()
    MoveEnemies(dt)
end

And move them smoothly on the client like so

while true do
    local dt = RunService.Heartbeat:Wait()
    MoveEnemies(dt)
end

With a minimal margin of error.

2 Likes

No theyre dofferent, basically at client is how much heartbeat the client’s computer have, and server is how much heartbeats does.the server have

I see, is there any way I can do something like I said in the post?

use remoteevents i guess

your code is fine

while delta time will not be the same every frame

they will add up to be the same after multiple frames

so what that means is after 10 seconds
both client and server will have a sum of delta time that equals 10

1 Like

But its also possible do it without looping at all

local startPosition = Vector3.new(0, 0, 0)
local endPosition = Vector3.new(0, 0, 50)
local magnitude = (endPosition - startPosition).Magnitude
local direction = (endPosition - startPosition).Unit
local speed = 4
local startTime = os.clock() -- send this start time to the client so they can calculate the position as well

local function GetPosition()
    local deltaTime = os.clock() - startTime
    local movedAmount = math.min(speed * deltaTime, magnitude)
    return startPosition + direction * movedAmount
end

print(GetPosition())
task.wait(1)
print(GetPosition())
task.wait(5)
print(GetPosition())
task.wait(2)
print(GetPosition())

This took me a bit to understand but it makes sense, I should just use a single task.wait() with a number parameter, because even though the framerate doesn’t match, delta time does.

so the get GetPosition() function does not care how often you call it

it is always able to calculate the correct position based on the startTime

so you would only need to call the GetPosition() every time the tower shoots no need for a loop

1 Like