I’m working on my first game and ran into some odd behavior when trying to compensate for lag so I created a basic project to try and replicate what I’m seeing.
In the following video I have an NPC that moves between to parts in the workspace. The server window is on the left, the client on the right. I have Incoming Replication Lag set to 0.25 to simulate some bad lag/ping. The script is a server script located in ServerScriptService, the code for it is below the video.
When the session starts the client NPC is lagging behind the server NPC like I would suspect for a client with a high ping and no compensation being applied. After a couple passes between the two parts the Server NPC freezes for a split second while the client NPC jumps ahead at that exact same time. Now the client NPC is ahead of the server NPC, however I suspect the client NPC is just where the server NPC should be.
My question is why does the server NPC freeze up like that? I was hoping that the server window would be a reliable indication of the true location of the NPC on the server so I could at least see if my lag compensation is working or not in the client (lag compensation is not in this project).
Video:
Script:
local dummy = game.Workspace.Dummy
local p1 = game.Workspace.Part1
local p2 = game.Workspace.Part2
local connection = nil
local funcs = {}
local function arrivedAtP1(bComplete)
print("P1: "..tostring(bComplete))
connection:Disconnect()
dummy.Humanoid:MoveTo(p2.CFrame.Position)
connection = dummy.Humanoid.MoveToFinished:Connect(funcs[2])
end
local function arrivedAtP2(bComplete)
print("P2: "..tostring(bComplete))
connection:Disconnect()
dummy.Humanoid:MoveTo(p1.CFrame.Position)
connection = dummy.Humanoid.MoveToFinished:Connect(funcs[1])
end
funcs[1] = arrivedAtP1
funcs[2] = arrivedAtP2
dummy.Humanoid.WalkSpeed = 6
dummy.Humanoid:MoveTo(p2.CFrame.Position)
connection = dummy.Humanoid.MoveToFinished:Connect(arrivedAtP2)