#Event is not firing
1 messages · Page 1 of 1 (latest)
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)
you never call the function
I accidently delete that but same issue
not sure why is happening then, i had similar problems before with the Added thing
my solution was making a server script
just put a script in server script and put this:
local function Added(child)
print(child)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local backpack = player:WaitForChild("Backpack")
backpack.ChildAdded:Connect(Added)
end)
end)
but i needed for client side
why
i just see what the problem is
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
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)
Is it fixed
What event are u even trying to fire
i guess the .childAdded
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
new backpack is in clear the players items?
this should work 👍
or put this in startercharacterscripts
you'll also want to loop through anything that already exists in the backpack instead of relying exclusively on childadded
no as in the backpack container gets destroyed, so if you have any links to it like childadded, those get destroyed too
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
that makes alot more sense now
does that do the same thing as :WaitForChild(backpack, 5)
or am i misunderstanding how waitforchild works
you are misunderstanding how it works go look it up in the docs
ok
generally you almost never want to use that second parameter
if you need to use it then something else went wrong before that point
so what u mean is the bagpack that im getting is previous one?
if that is true could you write me a code that could successfully run client side?
you don't pay me enough to do that