TL;DR: Tool in backpack gets destroyed after travelling long distance holding it/changing teams while holding it. This doesn’t happen when the tool is in the backpack.
I’ve had a previous issue like this before, but that topic was closed automatically and I have since changed my tool system. No solutions on other topics like this that I found helped.
I’m experiencing an issue where if you change team or teleport over a larger distance on your current team, ~2 seconds afterwards the tool you are holding in your character dissapears/has the handle destroyed.
With the core Roblox backpack UI, the entire tool itself gets destroyed. With my own backpack UI, it detects the parent change and the tool is re-parented to the target. However, for my tool that includes a part (not the handle, RequiresHandle is unticked and using it produces the same issue) the part is destroyed, which then leads to infinite yield warning in my script and the entire script breaks for that tool.
I think it may have something to do with my backpack UI, because the part can’t be re-parented after the tool was.
Creating a tool object:
function Tool.new(target: Tool, keybind: number, reference: string): ToolClass
local self: ToolClass = setmetatable({}, Tool) --create object
--initialise values
self.Connections = {}
self.Equipped = false
self.Reference = reference
--create the gui element
local toolFrame = framework:Clone() --clone structure frame
toolFrame.Parent = display --parent to display
toolFrame.ToolIcon.Image = target.TextureId --assign tool icon
toolFrame.Keybind.Number.Text = keybind --assign keybind
toolFrame.Name = target.Name
self.GUIElement = toolFrame --assign to the tool object
--make tweens for the GUI element
self.Tweens = {
["EquipTween"] = ts:Create(self.GUIElement, info, {BackgroundColor3 = heldColour}),
["UnequipTween"] = ts:Create(self.GUIElement, info, {BackgroundColor3 = defaultColour})
}
--assign the tool
self.Tool = target
self.KeyCode = keybind
toolObjects[reference] = self
--return the new tool
return self
end
Toggling a tool:
function Tool:Toggle(): nil
--parent the tool depending on it's current parent
local currentParent = self.Tool.Parent
--tool is currently parented to the character, parent it to the backpack
if currentParent == character then
--get currently equipped tools
local currentlyEquipped: {ToolClass?} = Tool.GetEquippedTools() or Tool:GetTools()
--unequip this tool
humanoid:UnequipTools()
self.Tweens.UnequipTween:Play()
self.Equipped = false
--tool is currently parented to the backpack, parent it to the character
elseif currentParent == backpack then
--get currently equipped tools
local currentlyEquipped: {ToolClass?} = Tool.GetEquippedTools() or Tool:GetTools()
--equip the new tool
humanoid:EquipTool(self.Tool)
self.Tweens.EquipTween:Play()
self.Equipped = true
end
end
Any help is appreciated, this bug is really annoying me now…