Hello guys, I am working on a shooter game and I need my right arm to face the direction of the mouse. The script I have works, but when I face backward, the arm seems to go slightly back as well.
Is there any way to fix this or limit how far the arm turns?
script:
local armOffset = char.Torso.CFrame:Inverse() * (char["Right Arm"].CFrame * CFrame.new(0,0.5,-0.5))
local armWeld = Instance.new("Weld")
armWeld.Part0 = char.Torso
armWeld.Part1 = char["Right Arm"]
armWeld.Parent = char
RunService.Heartbeat:Connect(function()
if debounce == true then
armWeld.Parent = char.Torso
local cframe = CFrame.new(char.Torso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
armWeld.C0 = armOffset * char.Torso.CFrame:toObjectSpace(cframe)
else
armWeld.Parent = game.Lighting
armWeld.C0 = char.Torso["Right Shoulder"].C0 * CFrame.new(0,0,0)
end
end)
(the gun in the video is for testing)
Thank you.