#Issues with Backpack events

11 messages · Page 1 of 1 (latest)

willow tinsel
#

In my script, the first time the player joins, the ChildAdded event and ChildRemoved event do not work. When the player respawns, the ChildRemoved event begins to work, but the ChildAdded event still does not work. Can someone help me with this? All code is done in a local script.

local conadd:RBXScriptConnection = player:WaitForChild("Backpack").ChildAdded:Connect(AddInventory)
local conrem:RBXScriptConnection = player.Backpack.ChildRemoved:Connect(RemoveInventory)
repeat task.wait() until player.Character ~= nil and player.Character.Parent == workspace.Alive
SpawnInventoryFirst()
player.CharacterAdded:Connect(function(character)
    conadd:Disconnect()
    conrem:Disconnect()
    SpawnInventory()
    conadd = player.Backpack.ChildAdded:Connect(AddInventory)
    conrem = player.Backpack.ChildRemoved:Connect(RemoveInventory)
    
    character.ChildRemoved:Connect(function(child)
        if child:IsA("Tool") and child.Parent == player.Backpack then
            for i, v in pairs(player.PlayerGui.Toolbar.BG:GetChildren()) do
                if v:IsA("Frame") then
                    v.UIGradient.Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0, 0.8), NumberSequenceKeypoint.new(1, 0.5)})
                    v.BackgroundColor3 = Color3.new(0, 0, 0)
                end
            end
        end
    end)
end)
zenith crystal
#

never use repeat wait() until to wait for something

#

if you appreciate the life of your game

willow tinsel
#

Okay, but what about the events?

#

@zenith crystal

zenith crystal
#

What does that script do?

#

What do you want the script to do?

willow tinsel
zenith crystal
#

What is the conadd variable used for?

willow tinsel
runic cosmosBOT
#

studio** You are now Level 1! **studio