Hello! I do tools for my game and I need the upper part of the body (UpperTorso) to follow the camera. I made a script and does work but It doesn’t have a limit. You can rotate your body about 360°. I did look for solutions on Developer Hub, but I didn’t find anything.
Local Script:
local player = game:GetService("Players").LocalPlayer
local Camera = game.Workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
-- LowerTorso = UpperTorso
-- LowerTorso.Root = UpperTorso.Waist
-- I changed it from LowerTorso to UpperTorso because I thought that LowerTorso rotates the upper part of the body.
local lowerTorso = character:FindFirstChild("UpperTorso") or character:WaitForChild("UpperTorso")
local root = lowerTorso:FindFirstChild("Waist") or lowerTorso:WaitForChild("Waist")
local RC = CFrame.lookAt(root.C0.Position, root.C0.Position + Camera.CFrame.LookVector) -- RC means Waist.C0
local LTCF = CFrame.new(lowerTorso.Position) * root.C0.Rotation -- LTCF means UpperTorso.CFrame
game:GetService("RunService").RenderStepped:Connect(function()
RC = CFrame.lookAt(root.C0.Position, root.C0.Position + Camera.CFrame.LookVector)
LTCF = CFrame.new(lowerTorso.Position) * root.C0.Rotation
script.Parent.Event:FireServer(RC, LTCF)
end)
Server Script:
local event = script.Event
local char = script.Parent
local uppertorso = char:WaitForChild("UpperTorso")
local waist = uppertorso:WaitForChild("Waist")
event.OnServerEvent:Connect(function(player, RC, LTCF) -- player, Waist.C0 to set, UpperTorso.CFrame to set.
if player.Character == char then
waist.C0 = RC
uppertorso.CFrame = LTCF
end
end)