Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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().

This discussion is preserved as it was. New answers, comments, and votes are closed.