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)
** You are now Level 1! **