I tested it on another game same code and works fine, on a baseplate, but in my game, it doesn’t prints ‘a’ so it’s not urnning the function
Can anyone help?
I have no clue why it doesn’t works in baseplate but not in my game…
It doesn’t even makes sense.
Here you can see i’m literally CLONING the script and pasting it into the localscript that runs it (same interface and code), as you can see .ChildAdded works in baseplate but not in MY game… what the hell?
can someone tell me what’s wrong? It’s unbelievable.
There’s a silent bug in your event. They can be sneaky to debug, what I’d recommend doing is putting a breakpoint on the line (click next to the line number) where you print the connection in the event and step through it
If there are any issues with a conditional, stepping through it will make it instantly obvious which condition isn’t resolving as true, or if there is some other code misbehaving.
Yeah I believe it may be client vs server as @BuilderBob25620 said.
Try switching to server then drag the tool to backpack.
ChildAdded should still fire here since the code is running from the client.
Already did, and get the same results adding/removing it from server.
Ok now press the button called Step Into
under the Script tab to step through your code. Since the code is finishing (since there’s no errors), it’s better to visualise the computational flow of your program and not just what the functions do.
Also put it after the function()
, statement, it’s currently breaking when you connect the function, not when it runs
Oh apologies, then I will suggest some more ideas.
Once a character dies, the Backpack is removed and a new one will be created – populating
Usually this gets messy in a real game with stuff like player:LoadCharacter() as I have experienced with other help topics especially with GUIs. Sometimes the backpack gets destroyed then readded which destroys the connection.
I would also maybe do this to debug further.
local Player = game.Players.LocalPlayer
Player.ChildAdded:Connect(function(child)
if child.Name == "Backpack" then
print(child, "New backpack added!")
end
end)
ex: I click play and somehow there were two backpacks were created.
As you can see here, Player.Backpack.ChildAdded not working - #3 by varjoyTes
It was indeed connected so if it was destroyed it wouldnt be connected right?
Hi, when I clicked on Step Into it went from
.ChildRemoved straight to :GetChildren(), I guess there is a problem there uh??!?
Well yes it would be connected.
However it could be connected to the old backpack which is now is nil after being destroyed.
It will still exist in the script because the prints are holding a reference and prevent it from being garbage collected. Same thing as doing
Part:Destroy()
print(Part)-- prints the part
The new backpack would then not be connected, check the print order as well perhaps.
I have tried also :GetFullName() and it prints the path to the player, but ok, I’ll give a try to your solution!
yes, it prints new backpack added
never happened this to me before, why does this happens tho?
and how can I fix it?
I would put the backpack connection code within that new back pack code to always ensure the new backpack is connected.
either way, why does it works on a baseplate but not in MY game? like, what?
hey, it worked, weird error I never been through haha.
ended up doing this;
local BackpackCons = {}
local function ConnectBackpack()
for i,v in pairs(BackpackCons) do
v:Disconnect();
end;
BackpackCons[#BackpackCons + 1] = Player.Backpack.ChildRemoved:Connect(function(child)
local find = Player.Character:FindFirstChild(child.Name)
if (find == nil) then
for i,v in pairs(Backpack.Slots:GetChildren()) do
if (v:IsA("Frame")) then
if (v.TName.Text == child.Name) then
v.BackgroundTransparency = .7;
--v.Visible = false;
v.TName.Text = ''
end
end
end
end;
end)
BackpackCons[#BackpackCons + 1] = Player.Backpack.ChildAdded:Connect(function(child)
for i = 1,7 do
local slot = Backpack.Slots:FindFirstChild(i)
if slot then
if (#slot.TName.Text < 1) then
local continue = true
for i,v in pairs(Backpack.Slots:GetChildren()) do
if (v:IsA("Frame")) then
if (v.TName.Text == child.Name) then
continue = false;
end
end
end
if (continue == true) then
slot.TName.Text = child.Name;
--slot.Visible = true;
end
end
end
end
end)
end
ConnectBackpack()
Player.ChildAdded:Connect(function(child)
if child.Name == "Backpack" then
ConnectBackpack()
end
end)