Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this script apply to the Head only?

Asked by 4 years ago

Hey, I have a script that rotates a player based on their camera however I'd like it to only rotates the head of the player and not the full character? How would I do this?

Any help would be awesome!

Here is the script:

local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local dead = false
local heartbeat = nil


function LockToCamera()
    local pos = root.Position
    local camLv = camera.CFrame.lookVector
    local camRotation = math.atan2(-camLv.X, -camLv.Z)
    root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, camRotation, 0)
end


userInput.InputEnded:Connect(function(input)
    if (input.UserInputType == Enum.UserInputType.MouseButton2 and heartbeat) then
        heartbeat:Disconnect()
        heartbeat = nil
        humanoid.AutoRotate = true
    end
end)


userInput.InputBegan:Connect(function(input, processed)
    if (processed or dead) then return end
    if (input.UserInputType == Enum.UserInputType.MouseButton2) then
        humanoid.AutoRotate = false
        heartbeat = game:GetService("RunService").Heartbeat:Connect(LockToCamera)
    end
end)


humanoid.Died:Connect(function()
    dead = true
    if (heartbeat) then
        heartbeat:Disconnect()
        heartbeat = nil
    end
end)
0
Head.Orientation = CFrame.new(Head.Position,mouse.Hit.p) I think... greatneil80 2647 — 4y

Answer this question