Character Jittering when setting HumanoidRootPart CFrame / Orientation while walking

Problem:
I am making a game where player2 needs to always be facing the same orientation of player1 (forcefully)

but when player1 walks they start jittering and stuff and lag backing

Code I have on the server:

game:GetService("RunService").Heartbeat:Connect(function()
	player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * game.Players:FindFirstChild(userString.Value).Character.HumanoidRootPart.CFrame.Rotation
end)

Video:

External Media

try disabling the player’s movement?

For what I am making I need to have it so the player can move aswell

uhhhhh try changing the lookAt vector of player2 instead of the whole thing???

Can I have some sample code? I’ve never used lookAt

uhmm me neither…

limit

Always check the create.roblox.com site for the documentation.
CFrames | Documentation - Roblox Creator Hub shows how to make something face the same direction or at a certain point.

Dude did you even BOTHER reading before commenting that, or are u trying to farm replies?

1 Like

I can’t assume that you have read the documentation about lookAt. I was only providing the link if you didn’t know it was there.

The jittering and lag backing could be due to the constant updating of player2’s orientation to match player1’s. Instead of updating the orientation on every frame, you could try updating it at a set interval.

local updateInterval = 0.1 -- update every 0.1 seconds
local lastUpdate = 0

game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
	lastUpdate = lastUpdate + deltaTime
	if lastUpdate >= updateInterval then
		local player1 = game.Players:FindFirstChild(userString.Value)
		local player2 = game.Players.LocalPlayer
		if player1 and player1.Character and player2 and player2.Character then
			player2.Character.HumanoidRootPart.CFrame = CFrame.new(player2.Character.HumanoidRootPart.Position) * player1.Character.HumanoidRootPart.CFrame.LookVector
		end
		lastUpdate = 0
	end
end)

This script updates player2’s orientation to match player1’s every 0.1 seconds, which should reduce the jittering and lag backing. Adjust the updateInterval value to find a balance between what would work best for you.

I tried this and it didnt work