Setting Rotation with script make player fly

i made script which locks x,z rotation and keeps y rotation but, it just makes character fly

like this:

code:

local camera = game.Workspace.CurrentCamera
local character = game.Players.LocalPlayer.Character
local humanoid : Humanoid = character:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart

local RotationChangedEvent = Instance.new("BindableEvent")
local RCEvent : RBXScriptSignal = RotationChangedEvent.Event

local LastRotation = rootPart.Rotation

function OnEvent()
	rootPart.Rotation = Vector3.new(0,rootPart.Rotation.Y,0)
end

function Update()
	local CurrentRotation = rootPart.Rotation
	if LastRotation ~= CurrentRotation then
		RotationChangedEvent:Fire()
	end
end

RCEvent:Connect(OnEvent)
game:GetService("RunService").Heartbeat:Connect(Update)
1 Like

Use CFrames instead CFrame.fromOrientation and remember its in radians.

Using .Orientation or .Rotation breaks the weld and doesnt move the rest of the rig leading to buggy results.

1 Like