Custom backpack tool issue

I have made a custom backpack for my game. The only problem is that when you get eliminated in the game, if you hold the tool while getting eliminated (it’s in your character), it will completely dissapear out of the backpack and the character, essentially breaking the whole backpack script and not allowing you to equip or unequip the tool.

please do not get confused with my use of self here; it is the module, defined by colon notation. Although this system is not Object-Oriented, I preferred to use self here.

Toggler:

function inventory:ToggleTool(toolNumber:number) --toggle a tool (equip/unequip)
	if self.ItemEquippedDb == true then return nil end --no logic statement for table indexing
	self.ItemEquippedDb = true
	
	if not self.BoundTools[toolNumber] then
		self.ItemEquippedDb = false
		return nil 
	end
	
	local targetName = self.BoundTools[toolNumber]
	
	for _, item in ipairs(character:GetDescendants()) do
		if item:IsA("Tool") then
			item.Parent = backpack
		end
	end
	
	if self.EquippedTool == toolNumber then
		self.EquippedTool = 0
		self.ItemEquippedDb = false
		return nil
	end
	
	self.EquippedTool = table.find(self.BoundTools, targetName)
	
	local tool = backpack:WaitForChild(targetName, 5) or character:WaitForChild(targetName, 5)
	
	if not tool then return nil end
	
	if tool.Parent == character then
		tool.Parent = backpack
	else
		tool.Parent = character
		task.wait(0.1)
		local icon = display:FindFirstChild(tool.Name)
		if icon then
			local tween = ts:Create(icon, info, {BackgroundColor3 = Color3.fromRGB(175, 175, 175)})
			tween:Play()
			tween.Completed:Wait()
			tween:Destroy()
		end
	end
	
	task.wait(0.1)
	self.ItemEquippedDb = false
end

Input manager:

local function processInput(input:InputObject, processed:boolean)
	if processed then return nil end
	
	local keyCode = table.find(handler.keys, input.KeyCode)
	if keyCode then
		handler:ToggleTool(keyCode)
	end
end

Any help is appreciated, I’m stumped. By the way, the character does not die when getting eliminated, so it is not destroyed. The tool is not manually parented to nil.

This issue ONLY occurs when eliminated holding the tool, I have already tried making a procedure to unequip the tool on elimination.

is backpack the one that exists in the player or is it like a custom folder

I’m using the player backpack, parenting tools too and from it. Only the UI is custom.

Bumping this post, I still need help im really confused on why this is happening.

maybe try checking the player’s previous character for a tool before they respawn

Like I said before, the character does not die, so their character is never destroyed. The character when they respawn is the same one as when they were eliminated.

If it helps, I ran some code in the command bar to determine what data was changed:

  • The 3 parent ones was me equipping and unequipping, the others happened during elimination.

Anyone have any idea of what the issue might be?

Ok, looks like I managed to make a workaround. I just parented the tool to the backpack of the hit player in the eliminator method of my ball object.

Still confused why this happened, though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.