#ChildAdded not working
1 messages · Page 1 of 1 (latest)
u forget the get characteradded and character's backpack
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local backpack = player:FindFirstChild("Backpack")
if backpack then
backpack.ChildAdded:Connect(function(child)
print("tool added to backpack: " .. child.Name)
end)
end
end)
end)
Thank you, this worked
Why do you have to do this tho?
Shouldn't it just say that "Backpack" is nil if you try to index it to early?
because the Backpack doesnt exist until the character spawns
yes it would be nil if you try to access it too early the problem is that the Backpack gets created when the character spawns so if you try to access it before the players character loads you wont get an error but your script simply wont find it thats why you need to wait for the CharacterAdded event.
Alright, well thank you
This isn't true, the player's backpack is there before the character spawns.
In a game with CharacterAutoLoad off, OP's posted script works fine.
Sorry, I was thinking server-side, not client-side.
I put this in a script, both local and server, and it worked fine.
This is probably on then