I’m trying to rotate a part to always look where the player is looking (I have a custom character and the game is in first person so basically this will be the characters head)
The rotation detecting worked fine, and when on its own as just the part it all seemed to work, but when added to my StarterCharacter the world starts shaking up and down, the character cant move, and the rotation becomes laggy.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Events.RotateHead.OnServerEvent:Connect(function(plr, rotation, pos)
local char = plr.Character or plr.CharacterAdded:Wait()
char.HumanoidRootPart.Rotation = rotation
end)
And here’s the rotation detection, which works fine
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cam = workspace.CurrentCamera
function CFrameToOrientation(cf)
local x, y, z = cf:ToOrientation()
return Vector3.new(math.deg(z*-1), math.deg(y + 300), math.deg(x*-1))
end
cam:GetPropertyChangedSignal("CFrame"):Connect(function()
ReplicatedStorage.Events.Rotate:FireServer(CFrameToOrientation(cam.CFrame, script.Parent.HumanoidRootPart.Position))
end)
Is this even the best way to go about this? Again, the “head” is gonna be on a startercharacter and is just one part. Basically so other players can see where you are looking