Cleanup should be finished across Backpack/PlayerGui/Character before parenting anything new

Stuff in all of these locations are removed when the player respawns. The problem is that this is the order:

Delete character
Clear old backpack items
Load Backpack
Clear old PlayerGui items
Load PlayerGui
Create character

If you haven’t already noticed the problem, if I have a localscript in the StarterPack (goes into backpack) that uses WaitForChild to wait for something in the PlayerGui, WaitForChild will return the old instance right before it’s deleted before the new instance is loaded. Try having your script work with a nonexistent GUI – it won’t get very far. All items should be cleared out of all three of these containers before the new ones are created (new Backpack and Character are created on each respawn, and the PlayerGui just has its children cleared) and the new contents are added to prevent WaitForChild from being tricked. The order should look like this:

Delete character
Clear old backpack items
Clear old PlayerGui items
Load PlayerGui
Load Backpack
Create character

In addition to clearing everything first, you’ll notice I also made another change, and put loading the PlayerGui before loading the backpack (currently it’s in the reverse order). Tools in the backpack use UI from the PlayerGui, and generally not the other way around, so it makes sense to load the PlayerGui first.

5 Likes

I would rather tools loaded after the character, that way we can reference the character instantly in tools without having to check if the character is already loaded and wait for it if it isn’t.

Other than that this would make tool and ui scripting a lot nicer.

3 Likes