Tracking changes in the workspace value: GetServerTimeNow()

Hello, I need this for a one-time synchronization. Is there generally a simpler way to track when data replication from the server to the client has occurred?

That’s what I did:

local RunService = game:GetService("RunService")
local connects: {(number) -> ()} = {}

local GetServerTime = workspace.GetServerTimeNow
local lastServerTime = GetServerTime(workspace)

RunService.HeartBeat:Connect(function()
  local currentTime = GetServerTime(workspace)
  if currentTime <= lastServerTime then return end

  lastServerTime = currentTime

  for i, handler in connects do
    handler(currentTime)
  end
end)

return function(handler: (number) -> ())
  table.insert(connects, handler)
end

Could you explain a bit more what exactly is happening in your script? theres a few things that don’t make much sense to me

This will always return false, Heartbeats will always have a small time distance

Can you explain what your goal is here? I don’t think I understand what you’re trying to achieve. There is no absolute way to know when data replication has occurred; replication is constantly occurring.

And pro-tip: just call workspace:GetServerTimeNow() directly. No need to store it in a local variable (that was an old-school optimization technique that is no longer valid).

I am trying to synchronize the object’s position on the client once after it is created, and then the client will move the object on its own, independent of workspace:GetServerTimeNow()

Like this

ObjectCreationRemoteEvent.OnClientEvent:Connect(function(creationTime)
  local object = module.create()

  local newTime = workspace:WaitForNewServerTime()
  local diff = newTime - creationTime

  object:setStartObjectPositionOfMovingAnimation(diff)
  object:continueMovingAnimation()
end)

What kind of moving animation is it?

Manually using linear interpolation (lerp) and RunService.PreRender

If it’s linear thats perfect, you can add the speed it moves (in studs per second) multiplied by the time difference as a start position

1 Like