#Event is not firing

1 messages · Page 1 of 1 (latest)

brave basalt
#

i even did some debugging
btw bagpack is not nil

#
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local backpack = player:WaitForChild("Backpack")

local function Added(child)
    print(child)
end

backpack.ChildAdded:Connect(Added)
brave basalt
gaunt torrent
#

my solution was making a server script

gaunt torrent
brave basalt
gaunt torrent
gaunt torrent
#

local backpack = player:WaitForChild("Backpack") this is actually nil

#

not sure why, becouse u are using :WaitForChild

#

but if u put a task.wait(5) for example, it work

gaunt torrent
# brave basalt but i needed for client side

this is client side
task.wait(5)
local backpack = script.Parent.Parent:WaitForChild("Backpack")

local function Added(child)
print(child)
end

backpack.ChildAdded:Connect(Added)

ashen anvil
#

Is it fixed

ashen anvil
gaunt torrent
raven crater
#

player gets a new backpack whenever they respawn - it gets destroyed and a new one is created

#

this includes the initial spawn, so when you do player.Backpack in playeradded, their actual backpack is not this one

placid totem
raven crater
#

you'll also want to loop through anything that already exists in the backpack instead of relying exclusively on childadded

raven crater
#

its a weird roblox behavior idk why it does that, the docs dont mention it, but thats what happens. seen it before

#

it's why the task.wait(5) before fetching the backpack works - it's getting the second backpack when they actually spawn

#

also why fetching it on characteradded works

gaunt torrent
placid totem
#

or am i misunderstanding how waitforchild works

raven crater
placid totem
#

ok

raven crater
#

generally you almost never want to use that second parameter

#

if you need to use it then something else went wrong before that point

brave basalt
#

if that is true could you write me a code that could successfully run client side?

raven crater
#

you don't pay me enough to do that