Hello, I am working on a sword fight game and I made a script that rotates your arms relative to your camera when you are in first person, I want the script to only rotate your arms up and down, but it rotates them left and right too. I’ve been stuck on this for weeks and if I could get it to work i would be so happy
Video of the issue:
robloxapp-20220819-1744000.wmv (1.9 MB)
My code:
local player = game.Players.LocalPlayer
local humanoid = script.Parent:WaitForChild('Humanoid')
local humanoidRootPart = script.Parent:WaitForChild('HumanoidRootPart')
local rightShoulder = script.Parent:WaitForChild('Torso'):WaitForChild('Right Shoulder')
local leftShoulder = script.Parent:WaitForChild('Torso'):WaitForChild('Left Shoulder')
local rightOrigin = rightShoulder.C0
local leftOrigin = leftShoulder.C0
game:GetService('RunService').RenderStepped:Connect(function()
local cameraCFrame = game.Workspace.CurrentCamera.CFrame
if script.Parent:WaitForChild('Head').LocalTransparencyModifier == 1 and humanoid.Health > 0 then
rightShoulder.C0 = (cameraCFrame * CFrame.new(1, -1, -0.5)):ToObjectSpace(humanoidRootPart.CFrame):Inverse() * CFrame.Angles(0, math.pi / 2, 0)
leftShoulder.C0 = (cameraCFrame * CFrame.new(-1, -1, -0.5)):ToObjectSpace(humanoidRootPart.CFrame):Inverse() * CFrame.Angles(0, -math.pi / 2, 0)
else
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi / 2, 0)
leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi / 2, 0)
end
end)