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

How to change a player's rotation (locally)?

Asked by 4 years ago
Edited 4 years ago

I was just playing around with studio and tried this script with a button, but whenever I press it if the player's body isn't facing 0, 0, 0 it will just go crazy and the arms will break and legs. Heres the script:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
local playerg = player.Character:GetChildren()
    for i,v in pairs(playerg) do
        if v.ClassName == "Part" then
            v.Orientation = Vector3.new(0, 0, 0)
        end
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Use :SetPrimaryPartCFrame.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local playerg = player.Character or player.CharacterAdded:Wait()

    playerg:SetPrimaryPartCFrame(playerg:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0))
end)

playerg:SetPrimaryPartCFrame(playerg:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 0)) will set the CFrame by first gettings the primary part's CFrame and then adding 0 degrees. When using CFrame.Angles() make sure you use math.rad().

Ad

Answer this question