How to reset Motor6D on arms when tool is unequipped?

Hey everyone! I just started working with lerp, CFrame and all that and I’m using it to animate tools, which I know isn’t necessary but I just want to expand my knowledge further, nevertheless, I came up with this script that animates the Motor6D of the player’s arms, however, I haven’t been able to figure out how to reset them back to the original position. I’ve tried storing the original positions and then making them that when the tool is unequipped but that didn’t work. Any help would be fantastic, and I hope you have an amazing day! :slight_smile:

local tool = script.Parent

local original_LSC0
local original_RSC0

function equipanim()
	local player = game.Players:GetPlayerFromCharacter(tool.Parent)
	if player then
		local character = player.Character
		if character then
			local LS = character.Torso["Left Shoulder"]
			local RS = character.Torso["Right Shoulder"]

			local targetRSC0 = RS.C0 * CFrame.Angles(math.rad(0), math.rad(0), math.rad(40.012))
			local targetLSC0 = LS.C0 * CFrame.Angles(math.rad(0), math.rad(0), math.rad(-40.012))

			original_LSC0 = LS.C0
			original_RSC0 = RS.C0
			
			local time = 1  
			local step = 0.01  

			for i = 0, 1, step do
				RS.C0 = RS.C0:lerp(targetRSC0, i)
				LS.C0 = LS.C0:lerp(targetLSC0, i)
				wait(time * step) 
			end


			RS.C0 = targetRSC0
			LS.C0 = targetLSC0
		end
	end
end

function unequipanim()
	if original_LSC0 and original_RSC0 then
		local player = game.Players:GetPlayerFromCharacter(tool.Parent)
		if player then
			local character = player.Character
			if character then
				local LS = character.Torso["Left Shoulder"]
				local RS = character.Torso["Right Shoulder"]

				LS.C0 = original_LSC0
				RS.C0 = original_RSC0
			end
		end
	end
end

tool.Equipped:Connect(equipanim)
tool.Unequipped:Connect(unequipanim)

i dont know if this may work but uh, try this:

local original_LSC0 = CFrame.new(-1,0.5,0) * CFrame.Angles(0,math.rad(-90),0)
local original_RSC0 = CFrame.new(1,0.5,0) * CFrame.Angles(0,math.rad(90),0)

function equipanim()
	local player = game.Players:GetPlayerFromCharacter(tool.Parent)
	if player then
		local character = player.Character
		if character then
			local LS = character.Torso["Left Shoulder"]
			local RS = character.Torso["Right Shoulder"]

			local targetRSC0 = RS.C0 * CFrame.Angles(math.rad(0), math.rad(0), math.rad(40.012))
			local targetLSC0 = LS.C0 * CFrame.Angles(math.rad(0), math.rad(0), math.rad(-40.012))

			local time = 1  
			local step = 0.01  

			for i = 0, 1, step do
				RS.C0 = RS.C0:lerp(targetRSC0, i)
				LS.C0 = LS.C0:lerp(targetLSC0, i)
				wait(time * step) 
			end


			RS.C0 = targetRSC0
			LS.C0 = targetLSC0
		end
	end
end

function unequipanim()
	if original_LSC0 and original_RSC0 then
		local player = tool.Parent.Parent
		if player then
			local character = player.Character
			if character then
				local LS = character.Torso["Left Shoulder"]
				local RS = character.Torso["Right Shoulder"]

				LS.C0 = original_LSC0
				RS.C0 = original_RSC0
			end
		end
	end

i hope this solves your problem.

1 Like