How do I teleport a tool back where it should be?

I made it so when I right click with my gun it moves in front of my head. I want to make it so when I stop holding it teleports where it should be in the hand.

I tried saving the old position of the gun when I am aiming and then setting it back to the saved position when I stop holding click but if I move at all the gun will teleport where I was before.

I want to teleport the gun in a way where it is at the hand based on its grip maybe. Idk how. Also the game is R6.

local function OnInput(input :InputObject, processed)
	if processed or not Equipped or OnCooldown then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		Aiming = true
		while Aiming and Equipped do
			if not OldPositon then
				OldPositon = Handle.Position
			end
			local Head = Char.Head
			Handle.Position = Head.Position
			task.wait()
		end
	end
end

local function OnInputEnded(input :InputObject, processed)
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton2 and Equipped then
		Aiming = false
		if OldPositon then
			Handle.Position = OldPositon
		end
		OldPositon = nil
	end
end

UIS.InputEnded:Connect(OnInputEnded)

UIS.InputBegan:Connect(OnInput)

-- I didnt put the variables at the start in the script and the check if 
-- it is equipped because they are not important for this

Motor6D or WeldConstraints.
character

What do you mean? How should I use a Motor6D or WeldConstraints?

As he said, minimally, you may use Motor6Ds to change the gun’s position via the property Motor6D.Transform. Attach the Handle to the Arm using Motor6D’s Part0 and Part1 properties, then use CFrames to adjust the offset of the Handle.

I’d say it’s better to create gun animations with the Animation Editor or external software instead of procedurally animating it.