#Placeholder backpack instance causing issues

1 messages · Page 1 of 1 (latest)

azure quail
#

I encountered a bug where apparently Roblox changes the player backpack instance. My localscript is set up to immediately create a backpack.ChildAdded event listener, which is problematic for me because it ends up setting up the event on the initial backpack instance, but then the backpack instance is switched, rendering the old one obsolete and unused. This means that my event listener is obsolete as well, and ChildAdded will never receive a signal when a new tool is added to the backpack. To give a demonstration, see the following code:

local function ListenForNewTool()
    local backpack = Players.LocalPlayer:WaitForChild("Backpack")
    local potential_tool = backpack:FindFirstChild("Eyecatcher")
    if potential_tool then
        UpdateTool(potential_tool)
    end
    
    while true do
        RunService.Heartbeat:Wait()
        print(Players.LocalPlayer:FindFirstChild("Backpack") == backpack)
    end
    
    backpack.ChildAdded:Connect(function(child)
        print("f")
        UpdateTool(child)
    end)
    
    while not is_tool_initialized do
        ToolInitialized.Event:Wait()
    end
end

The script captures the initial backpack instance, and then repeatedly compares it to the current version of the backpack instance in a while true do loop. In the attached image, notice how after a few frames, the script acknowledges that the backpack instance has changed. Has anyone encountered this bug before, and if so, is there a workaround or solution to this?

brazen cliff
# azure quail I encountered a bug where apparently Roblox changes the player backpack instance...

While I'm not 100% sure this is the cause, I'm fairly certain it's because roblox removes the original backpack instance very shortly after the player joins and creates a new one with the contents of the starter pack inside of it. When testing this, I had it print out the contents of the backpack after I put a blank tool inside of starterpack, and the results showed that the original backpack (when it prints true) printed an empty table, where the new one (when it prints false) printed the contents of it

azure quail
#

i never knew the old backpack got deleted, i always just assumed it cleared the children so this is news to me

#

and it's pretty annoying behavior that it gives you what's essentially a dummy backpack placeholder prior to the character's first load, which has no use because it's just going to get replaced once the character spawns in