Hello! I do tools for my game and I need to body (lower torso) face the same as the camera but only up and down. I made a script and it doesn’t work right. Sometimes body face on the other side. I did look for solutions on Developer Hub but I didn’t find what I want.
Local Script:
local Char = game:GetService("Players").LocalPlayer.Character
local Torso = Char:WaitForChild("Torso", 1)
local Head = Char:WaitForChild("Head")
local Root = Char:WaitForChild("HumanoidRootPart")
local Humanoid = Char:WaitForChild("Humanoid")
local Evt = script.Parent:WaitForChild("Evt")
local TorsoJoint = Char:WaitForChild("LowerTorso")
local CamCF = CFrame.new()
local OriginalTorsoCF = Char:WaitForChild("LowerTorso").Root.C1
local CurrentZRot = 0
local ANGLE_LIMIT_X = {-65, 50} --Down, Up
local ANGLE_LIMIT_Y = {0, 0} --Left, Right
game:GetService("RunService").RenderStepped:Connect(function ()
if Humanoid.Health <= 0 then
return
end
local RootRX, RootRY, RootRZ = Root.CFrame:toOrientation()
local RootRotation = CFrame.fromOrientation(-RootRX, RootRY, RootRZ)
local CamRotX, CamRotY, CamRotZ = workspace.CurrentCamera.CFrame:toOrientation()
local CamRot = CFrame.fromOrientation(
CamRotX * -1,
CamRotY,
CamRotZ
)
local Rotation = RootRotation:toObjectSpace(CamRot)
local RX, RY2, RZ = Rotation:toOrientation()
local RX = math.rad(math.clamp(math.deg(RX), unpack(ANGLE_LIMIT_X)))
local RY = math.rad(math.clamp(math.deg(RY2), unpack(ANGLE_LIMIT_Y)))
Rotation = CFrame.fromOrientation(RX * -1, RY * -1, RZ * -1)
Evt:FireServer(OriginalTorsoCF * Rotation)
end)
Server Script:
local Evt = script:WaitForChild("Evt")
local Char = script.Parent
Evt.OnServerEvent:Connect(function (Client, CF)
if Client.Character == Char then
Char:WaitForChild("LowerTorso").Root.C1 = CF
end
end)