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.