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