I want to say NetworkOwnership can play a role here, but I wouldn’t have expected it to cause a desync in rendering..
Assuming youre handling the NPC on the server, make sure that when it spawns you set the network ownership of all parts under the rig to nil so the server stays in control.
On the client, just make sure its not doing anything to the npc rig. If the client welds or created anything under the rig it may cause the rendering desync unless you made sure it has no way of interferring with the rig physics (i.e, you made anything the client created massless).
I changed the code to constantly set the network ownership to nil, same result though.
Or is there something wrong with my code? Theres no errors AFAIK.
task.wait(3) -- makes sure parts are loaded, player shouldn't get to the enemy this fast anyway
const parts = script.Parent:GetDescendants() -- const so it doesnt change.
game.RunService.Stepped:Connect(function()
for _,part in pairs(parts) do
if part:IsA("BasePart") then
part:SetNetworkOwner(nil)
end
end
end)
if you turn the red hitbox into a distance check instead (or do a distance check when the player touches the hitbox on the server), then you could grab the ping of the user and add it to the distance between the player and the npc. saying this because i assume the issue is that there is a delay between the replication on the server to the client and vice-versa.
this happens likely because of server client desynchronization because i have experienced this in many roblox games and its probably caused by slow internet
This is not a network ownership issue, assuming you have normal character controls and the NPC uses MoveTo(). This is just normal client-server desync as others have explained…
In any Roblox game, other players you see on your screen are actually in the past due to ping since it takes time for the client’s position to replicate to the server then to other players. In your case, let’s say you have a 20ms ping, the server will see your position 20ms in the past, which explains why on the left side of your video, you’re actually closer to the NPC and thus taking damage.
Understanding the client-server model really helps with this. And this is one issue that Server Authority aims to fix using client prediction.
The easiest way is to use magnitude checks (which you can manually adjust to account for ping, or calculate the player’s ping and adjust the final value). This is what a simple magnitude check looks like:
local DAMAGE_RADIUS = 7 -- how far from the npc players will start taking damage from
local magnitude = (plrHrp.Position - npcHrp.Position).Magnitude
if magnitude >= DAMAGE_RADIUS then
-- use trig to calculate if the player is in front of the npc
-- take damage
end
Also one tip: Don’t use Touched events for detecting moving objects - it will most likely always have a delay due to client-server replication.