Parent property locked on tool

I have a inventory with tools in it, how it works is that If you press on a equip button, you equip it, I do this by first deleting everything in your inventory then making a clone of a tool and parenting it to your backpack, however, I get this error/warning? - exception while signaling: The Parent property of Axe is locked, current parent: NULL, new parent
This is especially odd though, because this error only happens if I press they key bind for the tool, which is 1, but when I press the tool in the tool bar with my mouse, I can equip and unequip it.
This is a snippet of the code that is essential to this topic:

if isEquipping == true and isBought == true then
					if shopType == "axe" then
						dataManager:UnequipTools(player)
						dataManager:EquipTool(player,name,true)
						for _, v in next, char:GetChildren() do
							local tool = v
							if v:IsA("Tool") then
								if tool:FindFirstChild("axeHandler") then
									tool:Destroy()
								end
							end
						end
						for _, v in next, player.Backpack:GetChildren() do
							local tool = v
							if v:FindFirstChild("values") then
								if tool:FindFirstChild("axeHandler") then
									tool:Destroy()
								end
							end
						end
					end
					if shopType == "backpack" then
						dataManager:UnequipBackpacks(player)
						dataManager:EquipBackpack(player,name,true)
						for _, v in next, char:GetChildren() do
							local backpack = v
							if v.Name == "Backpack" and v:IsA("Model") then
								backpack:Destroy()
							end
						end
					end
					player.PlayerGui:WaitForChild("ScreenGUI"):WaitForChild("buyPrompt"):WaitForChild("interact").Text = "Equipped"
					local folder = game.ReplicatedStorage:FindFirstChild(""..shopType.."s")
					if folder then
						for _, v in next, folder:GetChildren() do
							local item = v
							if shopType == "axe" then
								if v.Name == name then
									local clonedTool = item:Clone()
									clonedTool.Parent = player.Backpack
									char:WaitForChild("Humanoid"):UnequipTools()
									char:WaitForChild("Humanoid"):EquipTool(clonedTool)
									clonedTool.Name = shopType:lower():gsub("^%l", string.upper)
									player.PlayerGui:WaitForChild("ScreenGUI"):WaitForChild("buyPrompt"):WaitForChild("interact").Text = "Equipped"
								end
							end

Thanks! I also understand that this error I get only happens if you try reparenting a object that is destroyed, but that doesn’t seem to be exactly the case because I destroy everything in my inventory then make a new clone and parent it to my backpack, so the thing in my backpack can’t be destroyed, after all I can still equip it by pressing the tool in the tool bar rather than pressing the keybind.

Perhaps add a if check to see if its nil or its parent is nil?

if it was nil then I wouldn’t be able to equip it by pressing the tool in the tool bar, but in a script I did check it and it prints the tool meaning it exists

I forgot to mention that it suddenly works after pressing the key bind what seems to be a arbitrary amount of times, when im testing sometimes it worked after pressing it 5 times, then 10 times, etc, it seems random then the key bind works again for the tool.

Im not familar with next
what does it do?

its the same as ipairs, just faster

its faster to type it I mean. -----------

Whats the difference betwen next, ipairs, and pairs
just proformance?

And also I suspect whatever datamanager variable is, is the cause.

it simply is a folder representing all the tools in your inventory, it is a bunch of bool values, has nothing to do with this.

If it is not nessasary you could use debris to add it to that with a extremely short cooldown and see what it does
(replace destroy with that)

what should the cooldown be? .1 seconds?

id put 0 HJTOJAGHSDJFGJSDFNGDFKJGNSG

nothing changed --------------------

word of advice
abandon this system it is weird
recode the entire thing wipe it clean
much faster then debugging this

nah -----------------------------

fixed it, I was using a custom toolbar and I realized that my events were being duplicated, I forgot I was using a custom tool bar, but yeah now I fixed it by putting the event into a variable and whenever the function (which the event is in) is called, before that I disconnect the variable and wallah now it works

words of advice:
never give up = will fix it