Head and torso movement in relation to camera movement

Also I totally destroyed this script since I made it depend on North Axis of the game… it doesn’t matter on HumanoidRootPart, only on Camera, so basically exactly what you said, since you never wanted it to depend on HumanoidRootPart :slight_smile: oops

Hello! I have deleted the server script to test for the client side issues. There are a few issues with the camera turning making the player move the opposite way, and also if it’s possible I’d love to incorporate some neck movement into it like my original script. I’ve attached another link with the output of the client script below.

https://gyazo.com/859413da21b7f08d6a77f30718a32527

Try this:

Server Script (ServerScriptService):

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game.Workspace
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local moveitmoveit = Instance.new("RemoteEvent")
moveitmoveit.Name = "moveitmoveit"
moveitmoveit.Parent = ReplicatedStorage

local function onCharacterAdded(character)
    local head = character:WaitForChild("Head")
    local humanoid = character:WaitForChild("Humanoid")
    local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
    local rigType = humanoid.RigType.Value == 0
    local torso = rigType and character:WaitForChild("Torso") or character:WaitForChild("UpperTorso")
    local neck = rigType and torso:WaitForChild("Neck") or head:WaitForChild("Neck")
    local waist = not rigType and torso:WaitForChild("Waist")
    neck.MaxVelocity = 0.2

    local u2 = false
    local C0 = neck.C0
    local CFrame_Angles = CFrame.Angles
    local math_asin = math.asin
    local u6 = 0.5  -- Reduced intensity
    local u7 = not rigType and waist.C0
    local u8 = 0.3  -- Reduced intensity
    local math_atan = math.atan

    moveitmoveit.OnServerEvent:Connect(function(player, cameraCFrame)
        if player.Character == character then
            local coordinateFrame = cameraCFrame
            if (rigType and character.Torso or character.UpperTorso) ~= nil and character.Head ~= nil then
                local lookVector = torso.CFrame.lookVector
                local p = head.CFrame.p
                if (not (not rigType) and not (not neck) or neck and waist) then
                    if not u2 then
                        local v15 = nil
                        local v16 = nil
                        v16 = (head.CFrame.p - coordinateFrame.p).magnitude
                        v15 = head.CFrame.Y - coordinateFrame.Y
                        if not rigType then
                            neck.C0 = neck.C0:lerp(C0 * CFrame_Angles(math_asin(v15 / v16) * 0.4, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u6, 0), 0.1)
                            waist.C0 = waist.C0:lerp(u7 * CFrame_Angles(math_asin(v15 / v16) * 0.2, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u8, 0), 0.1)
                        else
                            neck.C0 = neck.C0:lerp(C0 * CFrame_Angles(-(math_asin(v15 / v16) * 0.4), 0, -(p - coordinateFrame.p).Unit:Cross(lookVector).Y * u6), 0.1)
                        end
                    end
                end
            end
            humanoid.AutoRotate = true
        end
    end)
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(onCharacterAdded)
end)

for _, player in Players:GetPlayers() do
    if player.Character then
        onCharacterAdded(player.Character)
    end
end

Local Script (StarterPlayer → StarterCharacterScripts):

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game.Workspace
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local moveitmoveit = ReplicatedStorage:WaitForChild("moveitmoveit")

local function onCharacterAdded(character)
    local currentCamera = Workspace.CurrentCamera

    RunService.RenderStepped:Connect(function()
        if character:FindFirstChild("HumanoidSeat") then
            local seat = character.HumanoidSeat.SeatPart
            if seat and seat:IsA("VehicleSeat") then
                return -- Disable movement in driver's seat
            end
        end
        
        moveitmoveit:FireServer(currentCamera.CFrame)
    end)
end

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(onCharacterAdded)
end)

for _, player in Players:GetPlayers() do
    if player.Character then
        onCharacterAdded(player.Character)
    end
end

This time around, the code uses the moveitmoveit event to synchronize the upper body movement between the client and server. It also checks if the player is in a driver’s seat and disables the movement if they are.

Add a do after the for loop. Simple. Read what the error says next time and try doing it yourself. If you rely on others all the time then you’ll stay a beginner forever.