Motor6d Equipping Glitch

Hello! I am encountering this weird glitch that I cant fix.

Basically when you equip the gun it sits in the middle of the torso. However it only does this the second time you equip it, the first time it works perfectly fine!

There also seems to be a glitch where if you reconnect the motor6d to something else and then back to the gun it works.

Example:

Here is my equip and dequip code:

remotes.Equip.OnServerInvoke = function(player, action, weaponName, character)
	if action == "Equip" then
		local weapon = game.ReplicatedStorage.Weapons:FindFirstChild(weaponName):Clone()
		weapon.Parent = character
		
		local motor6d = Instance.new("Motor6D", character.Torso)
		motor6d.Name = "Attach"
		
		motor6d.Part0 = character.Torso
		motor6d.Part1 = weapon.RootPart
		
		return weapon, motor6d
	else
		local weapon = character:FindFirstChild(weaponName)
		weapon:Destroy()
		
		local motor6d = character.Torso:FindFirstChild("Attach")
		motor6d:Destroy()
	end
end

Maybe if you attached the motor6d to the arm the gun is being held the gun floating in the torso would be less noticeable, i’ve also had that problem. It might be that it takes a millisecond to load the animation to the humanoid.

Don’t use the parent argument of Instance.new.

Parent the object after all properties have been set.

Using the parent argument of Instance.new have caused some issues for me in the past since setting properties after parenting is bad practice and can result in weird bugs, and is very performance inefficient as well.

It didnt help my problem but I will make sure not use the parent argument for future things.

I ended up fixing the problem by not deleting and cloning the motor6d every time. I just created it once and kept it and it worked!