Weird twitching on the server side when setting CFrame from LocalScript

I made a script that makes this enemy model lock on to a player (look at the player). I made it a LocalScript because I wanted the lock-on to not lag behind, and it is working. However, for some reason, the model seems to twitch on the server side while looking perfectly fine on the client side. I have set network ownership of all the model’s parts to the player.

LocalScript:

local RUN_SERVICE = game:GetService("RunService")

local MODEL = script.Model.Value
local MODEL_ROOT = MODEL.HumanoidRootPart

local PLAYER = script.Player.Value
local CHARACTER_MODEL = PLAYER.Character or PLAYER.CharacterAdded:Wait()

local function LookAtPlayer(CharacterModel: Model)
	local CharRoot: BasePart = CharacterModel.HumanoidRootPart

	MODEL_ROOT.CFrame = CFrame.lookAt(MODEL_ROOT.Position, CharRoot.Position)
end

RUN_SERVICE.RenderStepped:Connect(function()
	LookAtPlayer(CHARACTER_MODEL)
end)

Below is a video of what I am talking about. On the left is the server side, while the right is the client side.

Does anybody know why this happens or if there is a way to fix it?

1 Like

Have you tried smoothing its behavior with :Lerp()?

1 Like

I haven’t but Lerping wouldn’t get the result I want because the enemy’s orientation would start lagging behind. I want the enemy to lock immediately onto the player without any smoothing

1 Like

How is it showing on server if it’s a local script?

1 Like

By setting the network ownership of all of the model’s parts to the player

1 Like

Second question, why does it matter on the server if it’s intended for the player?

1 Like

Because the attacks will be server sided

Is a server script making the enemy move around the target? If it is then it might be because of the latency difference between the server sided moving script and the local script setting the look direction of the enemy.

1 Like

I am using a LinearVelocity to move the enemy model. No script is involved.

1 Like

Is there are any other ways to track a player model without lagging behind using a server script? If there is, I could use that instead of using a LocalScript.

1 Like

Furthermore, when I remove the LinearVelocity and have the enemy stay in one place, the model still twitches.

1 Like

because network updates every 1/30th of a second, no getting around this without custom replication… which is impossible
consider using physics constraints

1 Like

What do you mean by physics constraints? Could you send some documentation so I could read up on it?

1 Like

It worked, thanks for the suggestion

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