NPC does not move for half a second on the client sometimes

I have a script for my NPC that changes its walkspeed from 0 to 64 then back to 0 in a loop, which would be something like this:

while true do
humanoid.WalkSpeed = 0
task.wait(1)
humanoid.WalkSpeed = 64
task.wait(0.4)
end

But, when seeing it on the client, it first doesn’t start moving immediately once the walk speed is set to 64, yet seeing it on the server looks like it starts moving immediately.

However, after some time with the game running, the NPC seems to start to move immediately on the client side rather than the server side.

I know it has something to do with latency, but how can I make the NPC start moving immediately to the client, since it pretty much ruins the way the NPC moves.

Sorry if the explaination is bad. Any help will be appreciated though.

I believe this is due to serve latency.
Server latency is the amount of time it takes for something on the server to replicated on the client, and vice versa.

@Git4you is basically right, this is likely server latency.
However I would recommend using RunService.Stepped or RunService.PreSimulation for loops instead, as these events run on every frame, before the physics simulation.

1 Like

I know about the server latency, as mentioned:

but I was just wondering how you can make the NPC start moving immediately on the client side when the game just starts, instead of it relying on the server before the client.

I’m sure it is possible in some way, because eventually it starts to move instantly for the client, but not for the server.

Also, RunService.Stepped and RunService.PreSimulation didn’t fix the issue.

There’s not much you can do assuming it’s server latency issues. Try handling the NPC. on the client?

Okay so I found a solution to this.

You just have to set the humanoid root part’s network ownership to the player

HumanoidRootPart:SetNetworkOwner(plr)

Thanks for helping too!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.