Rotating head with camera and server replication

Hey, I was looking at this post from a year ago about a LocalScript that rotates your head to where you look sort of like in Jailbreak.

The solution was this script:

local CFNew, CFAng, CFtoObjectSpace = CFrame.new, CFrame.Angles, CFrame.new( ).toObjectSpace
local asin, pi, hpi = math.asin, math.pi, math.pi / 2

local Plr= game.Players.LocalPlayer

game:GetService("RunService").RenderStepped:Connect(function()
    if Plr.Character then
        local Root, Neck, Humanoid, Camera = Plr.Character:FindFirstChild("HumanoidRootPart"), Plr.Character:FindFirstChild("Neck", true), Plr.Character:FindFirstChild("Humanoid"), workspace.CurrentCamera
        if Root and Neck and Humanoid and Camera.CameraSubject then
            local R6 = Humanoid.RigType == Enum.HumanoidRigType.R6
            if Camera.CameraSubject.Parent == Plr.Character then
                local CameraDirection = CFtoObjectSpace(Root.CFrame, Camera.CFrame).lookVector.unit
                Neck.C0 = CFNew(Neck.C0.p) * CFAng(0, -asin(CameraDirection.x), 0) * (R6 and CFAng(-hpi + asin(CameraDirection.y), 0, pi) or CFAng(asin(CameraDirection.y), 0, 0))
            else
                Neck.C0 = R6 and CFNew(Neck.C0.p) * CFAng(-hpi, 0, pi) or CFNew(Neck.C0.p)
            end
        end
    end
end)

The problem is it works fine on the client, but the head’s rotation doesn’t replicate to the server. How can I get it to do this? I thought since the NetworkOwner of all parts in Player.Character are the Player, it should automatically replicate, but it doesn’t.

3 Likes

Fire a remote event like every 0.1 of a second with the Motor6D position, fire all clients on the server, excluding the client who fired the server and lerp the received position locally.

Not sure if I wanna spam the server several times a second. Is this how jailbreak does it?

There’s no other way. It’s just a few bytes of data, wont do much harm at all.

You could also only fire it when they move their camera a certain amount or when it stops moving.

2 Likes

^ Right, and the clients can smoothly interpolate between the positions.

1 Like