I have an odd glitch where on the client a NPC will show up in a different spot than the server. The client thinks that it’s in one place, but the server thinks it’s somewhere else. Here’s a video of this glitch:
https://youtu.be/--u3xvk7kCE (uploaded on YouTube because I couldn’t upload here for some reason.)
I don’t know exactly what could be causing this to happen; I don’t know of any way for a script to cause this to happen, so it’s completely unclear to me whether or not this is a problem that my game has caused. I think it may have something to do with the amount of network traffic between client and server, since my game frequently sends big tables over RemoteFunctions/RemoteEvents. It is also possible that the server might not be able to process the game logic for the NPCs. There is a script on the server that handles each NPC and updates their information table (but doesn’t send any requests/info to the client) every RunService.Heartbeat. This might be overloading the server, but I can’t tell.
Is there a guide to understand server load / network load? I’m pretty sure my game is intensive but I don’t know how to figure it out exactly. I can use the dev console to view the status of things like the Heartbeat event, but I have no idea how to evaluate that information.
Can we have a look at some code for the server and client that handles NPC movement.
Btw, you can monitor network traffic between the client and server in a window in studio.
while true do
if NPC.Humanoid.Health > NPC.Humanoid.MaxHealth/2 then
wait(1)
end
local angle = math.random(1,360) * math.rad(1)
local dir = Vector3.new(math.cos(angle), 0, math.sin(angle))
NPC.Move(dir)
if math.random() > .5 then
NPC.Humanoid.Jump = true
end
wait(math.random())
NPC.Move()
end
Basically, they just move and jump randomly and erratically, and do so at a higher frequency when at less than half health. Here’s the NPC.Move() function
NPC.Move = function(Direction)
if NPC.Data.Values.ControlMovement then
NPC.Humanoid:Move(Direction or Vector3.new())
end
end
Nothing here is super crazy or unordinary, that’s why I’m so perplexed by this bug. It’s all pretty standard, simple stuff.
Also, what window lets you monitor network traffic? I made a post recently asking for that but I didn’t get any response that answered my question. I remember there being something that let you see all the requests flowing between client/server through RemoteEvents or RemoteFunctions.
Is all this code server-side?
(30 char)
Yep, both extracts are from the server side. The second one is from the module that runs NPC’s and the first one is in the NPC’s model and interfaces with the NPC through that module. Though, that shouldn’t matter.
I know that setting network ownership to the user can help with physics, maybe it will help in your case to?
Otherwise I’d look at the latency by just printing some times out in the server and client to see how long before the trigger from the server reaches the client. It feels weird though that the client and server would be so out of sync as in your example.
1 Like
I think what I’ll do is set the network ownership to nil so that the client has to listen to the server to know where the NPCs are. The problem may be that the client is given ownership to the NPC and loses it but doesn’t think it lost it. Then the server and client are both calculating where the NPC is and coming up with different results. If the client never calculates it, that should never happen.
1 Like
A thing I can think of is doing the movement client-side and then asking the server if it’s a proper hit by getting the position and seeing if it’s hit, with a margin for delay.
So the server would tell all clients that an NPC is moving with the pattern A. All clients will then move that NPC with pattern A and if the user tries shooting at the NPC it would use the position from the client. If the client registers a hit then it would send a request to the server who would fetch the position it has and then decide if it’s a valid hit or not.
It also might be the NPC’s Animate script, which I didn’t make. I’ll look around in there and see if anything weird is going on.
I still have no idea how a script could cause this to happen though.
1 Like