Get parts from a tool when player joins

So my main problem is that when I try to get the model of the tool, when it’s added as the player joins it will return nil.

PlayerBackpack.ChildAdded:Connect(function(tool)
	print(tool:GetChildren())-- {} Empty Table
end)

I get that adding a delay would work in this case

PlayerBackpack.ChildAdded:Connect(function(tool)
    task.wait(2)
	print(tool:GetChildren())-- {Part1,Part2} tools parts
end)

Buuut stuff like ping might have the delay of the parts being added to the tool longer than 2 seconds.
I don’t want to have a 20-30 second delay for each tool even if I add a spawn().

What would be the best approach for this?
I’m pretty stumped because I don’t want to overcomplicate it by making a whole connection waiting out every ChildAdded of the tool.

You should probably check if the player has loaded in yet, you could try something like player:HasAppearanceLoaded()?

1 Like

I tried both HasAppearanceLoaded and game:IsLoaded but it has the same behavior.

I hope this is a studio issue and not something I will have to deal with in the actual published game.

That’s what WaitForChild is for.
You can also set the max time for it too if you expect the default 5 seconds is not enough.

Since every tool has a child named “Handle” (or at least I think every one does) this actually fixes my issue if I wait for the handle.

I didn’t realize I could actually use waitforchild in this instance.

I just hope it won’t break if a tool doesn’t have a part named Handle in it.

You could just wait to see if it has one Part. If it does then you can probably assume that the other parts are loaded as well (I may be wrong) so you won’t necessarily have to wait for just the Handle in case there isn’t one.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.