As you can see the upper part of the arm is always changing cause this is R6 which makes it look very bad
How can I rotate the arm around the same point?
Here is the local script parented to StarterCharacterScripts
local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = workspace.CurrentCamera
local Arm = script.Parent["Right Arm"]
local Torso = script.Parent.Torso
local MotorShoulder = Instance.new("Weld")
MotorShoulder.Part0 = Torso
MotorShoulder.Part1 = Arm
MotorShoulder.Parent = script.Parent
local ArmOffset = Torso.CFrame:ToObjectSpace(Arm.CFrame) * CFrame.new(1,0.5,-0.5)
while task.wait() do
local Target = Vector3.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y,2)
local lookat = CFrame.lookAt(Torso.Position,Mouse.Hit.Position) * CFrame.Angles(math.pi/2,0,0)
MotorShoulder.C0 = ArmOffset * Torso.CFrame:ToObjectSpace(lookat)
end
Here’s a working and more accurate version, because it looks at the mouse from the shoulder instead of the torso like your example:
local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = workspace.CurrentCamera
local Arm = script.Parent["Right Arm"]
local Torso = script.Parent.Torso
local MotorShoulder = Instance.new("Weld")
MotorShoulder.Part0 = Torso
MotorShoulder.Part1 = Arm
MotorShoulder.C0 *= CFrame.new(1.5,.5,0)
MotorShoulder.C1 *= CFrame.new(0,.5,0)
MotorShoulder.Parent = script.Parent
local originalC1 = MotorShoulder.C1
while task.wait() do
local worldShoulderCF = Torso.CFrame:ToWorldSpace(MotorShoulder.C0 * MotorShoulder.C1)
local lookAtCF = Torso.CFrame:ToObjectSpace(CFrame.lookAt(worldShoulderCF.Position, Mouse.Hit.Position))
local x, y, z = lookAtCF:ToOrientation()
x += math.pi/2
MotorShoulder.C1 = originalC1 * CFrame.fromOrientation(x, y, z):Inverse()
end
The arm rotates around an unstable point because you’re using a Weld without correctly setting the pivot (C0), making the arm’s position to shift each frame. You need to anchor the shoulder position and put rotation relative to that fixed point to keep it stable.
Instead of just giving a script, try helping people see what’s wrong and how to fix it. Giving answers doesn’t teach anything; explaining the reason behind it does.
He copied the script from a different post in the first place. I’m working under the assumption he doesn’t necessarily understand it, just needs it to work.
Yeah, I know. But it’s better to help him understand a little so he can fix it or change it later. Just giving code without explaining doesn’t help much.
Actually i need to understand what the script does. I think it’s a bad habit to just give people scripts without explaining how they work, So can you explain what you changed in the script?
Why did you use C1 not C0?
Ok, I went back to your original code in order to explain better. Let me know if you have any questions:
local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = workspace.CurrentCamera
local Arm = script.Parent["Right Arm"]
local Torso = script.Parent.Torso
local MotorShoulder = Instance.new("Weld")
MotorShoulder.Part0 = Torso
MotorShoulder.Part1 = Arm
MotorShoulder.Parent = script.Parent
-- Removed 'Torso.CFrame:ToObjectSpace(Arm.CFrame) * ' because it's not
-- necessary, all you need is the offset cframe by iteself.
-- Changed from 'CFrame.new(1,0.5,-0.5)' for more accurate arm placement.
local ArmOffset = CFrame.new(1.5, 0.5, 0)
while task.wait() do
-- Changed to just the hit position,
-- no need for this modification: 'Vector3.new(Mouse.Hit.Position.X, Mouse.Hit.Position.Y, 2)'
local Target = Mouse.Hit.Position
local shoulderFinalCF = Torso.CFrame:ToWorldSpace(ArmOffset * CFrame.new(0, -.5, 0))
-- Changed 'CFrame.lookAt(Torso.Position,' to 'CFrame.lookAt(shoulderFinalCF.Position,'
-- so that it is looking from the shoulder, not from the torso for better results.
local lookat = CFrame.lookAt(shoulderFinalCF.Position, Mouse.Hit.Position) * CFrame.Angles(math.pi/2,0,0)
-- Added '* CFrame.new(0, -.5, 0)' to move the arm down after it
-- starts looking at the target (to make it look like it's pivoting around the shoulder).
-- Note: Order matters in CFrame multiplication.
MotorShoulder.C0 = ArmOffset * shoulderFinalCF:ToObjectSpace(lookat) * CFrame.new(0, -.5, 0)
end