Tool thats parented to the backpack and is transformed into a model makes its model mess up

Hey, so I have been working on a custom inventory system that uses part of roblox default tool system, the system uses a viewport frame which has a model where the tools are placed when equipped, the tools get removed after they get removed from the backpack or character.

However, I have noticed that when the tool is placed in the player’s backpack, the model cloned in the viewport frame looks messed up, I have spent more than a week trying to figure out the bug, with no luck.

-- The function which updates the gui, only showing the part where it clones the model since its the one thats giving the problem.

local GetRotateModelPart = RotateModel[Tools:GetAttribute("SlotNumber") or 1]
	GetRotateModelPart.Model:ClearAllChildren()
	
	GetRotateModelPart:SetAttribute("ToolTip", Adding and Tools.ToolTip or nil)
	GetRotateModelPart:SetAttribute("Tool", Adding and Tools.Name or nil)
	
	UpdateInformation()
	
	if not Adding then return end
	for i, Parts:Instance in ipairs(Tools:GetChildren()) do
		if not Parts:IsA("BasePart") then Parts:Destroy() continue end
		local NewPart = Parts:Clone()
		NewPart.Parent = GetRotateModelPart.Model
		if NewPart.Name ~= "Handle" then continue end
		GetRotateModelPart.Model.PrimaryPart = NewPart
	end
	GetRotateModelPart.Model:PivotTo(GetRotateModelPart.CFramePart.CFrame)

-- the events to call the update gui functions
Backpack.ChildAdded:Connect(function(Child)
	UpdateGui(Child, true)
end)
Backpack.ChildRemoved:Connect(UpdateGui)

Character.ChildAdded:Connect(function(Child)
	UpdateGui(Child, true, true)
end)
Character.ChildRemoved:Connect(function(Child)
	UpdateGui(Child, false, true)
end)

I have tried everything, I even tried looking at several other posts in the forums to find an answer, however it doesn’t seem like anyone is having the same problem

Cloned tool, thats parented to the character when its transformed into a model and parented to the viewportframe 3d inventory model.

Cloned tool, thats parented to the backpack when its transformed into a model and parented to the viewportframe 3d inventory model.

Constantly taking them out and in will cause these bugs. What I suggest you to do is clone the model when the player picks it up and parent it to the ViewportFrame; you won’t need to touch it again. Then I suppose you could destroy the viewport when the tool is taken out of the player completely. I assume you clone a template frame that will hold the model whenever something is added to the backpack?

I’ve tried to do this but I can’t really think of a good way to know when the player has the tool (character or backpack) or doesn’t have it, the current system makes it that when the tool goes from the backpack to the character, it fires both of the ChildAdded and ChildRemoved, which make the function fire twice, I’m trying to look for a way to detect the player having the tool wherever it is the backpack or the character that doesn’t fire the function twice (sorry if my explanation its confusing, english isn’t my first language lo)

You dont need to manage child events for both character and backpack. Just pick one to listen for:
Lets say you picked up a sword. Backpack’s ChildAdded is fired. Then instead of listening for when a child is added to the character when you equip the sword, listen for when the child is removed from the backpack. This just keeps it straighforward