Help with Motor6D not resetting

I’m updating the C0 property of the Left Shoulder and Right Shoulder Motor6D to point towards the mouse and that part works, here’s the code for that part which gets ran by RunService.Stepped.

function Weapon:MoveArmsToMouse()
	assert(self.Character)
	if not (self.Character.Parent) then return end
	if not (self.Tool.Parent == self.Character) then return end
	local LeftShoulder = self.Character:FindFirstChild("Left Shoulder", true)
	local RightShoulder = self.Character:FindFirstChild("Right Shoulder", true)
	local MousePosition
	local ViewportSize
	pcall(function()
		MousePosition = ReplicatedStorage.Functions.MouseFunction:InvokeClient(self.Player, "get_pos")
		ViewportSize = ReplicatedStorage.Functions.MouseFunction:InvokeClient(self.Player, "get_viewport_data")
	end)

	if not MousePosition or not ViewportSize then return end
	local Y = math.clamp((MousePosition.Y + 105) - (ViewportSize.Y / 2), -10, 30)

	LeftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, math.rad(-90), math.rad(Y))
	RightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.rad(90), math.rad(-Y))
end

Then when the tool is unequipped I run this function (I’ve already tested and it runs) which should reset the C0 to it’s original value, but as you can see from the video it does not.

function Weapon:ResetArms()
	assert(self.Character)
	local LeftShoulder = self.Character:FindFirstChild("Left Shoulder", true)
	local RightShoulder = self.Character:FindFirstChild("Right Shoulder", true)
	if not LeftShoulder or not RightShoulder then warn("no stuff ig") return end

	LeftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, math.rad(-90), 0)
	RightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.rad(90), 0)
end

Here’s the video

Any help is appreciated! Thanks!

It looks like you are setting the C0 values in your ResetArms function to the same values as in your MoveArmsToMouse function, except for the Y rotation.

In your ResetArms function, try setting the Y rotation to 0 instead of the math.rad(-90) and math.rad(90) that you have in your MoveArmsToMouse function. This should reset the arms to their original positions without the Y rotation applied.

Here’s the updated ResetArms function:

function Weapon:ResetArms()
    assert(self.Character)
    local LeftShoulder = self.Character:FindFirstChild("Left Shoulder", true)
    local RightShoulder = self.Character:FindFirstChild("Right Shoulder", true)
    if not LeftShoulder or not RightShoulder then 
        warn("no stuff found") 
        return 
    end

    LeftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, math.rad(-90), 0)
    RightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.rad(90), 0)
end

This should reset the C0 values of the Left Shoulder and Right Shoulder back to their original positions without the Y rotation. Let me know if this helps!

(idk if it will work…)

The point is that the Y axis is the only axis I’m modifying so setting it back to 0 should work and it does not. Also the code you provided doesn’t work unfortunatly.

1 Like