Creating Instances After Character

I’ve been trying to make Folders onto the character. The problem is that sometimes these folders don’t create. I’ve tried these solutions so far, most of the time it makes the instances, but sometimes it doesn’t create.

Solutions I’ve Tried:

–waiting for char
local character = player. Character or player.CharacterAdded:Wait()

–waiting until the whole character appearance loads
player.CharacterAppearanceLoaded:Connect(function()

–when character gets added
player.CharacterAdded:Connect(function()

All these solutions work just fine, it’s just sometimes the instances after doesn’t get created

How did you define player?

if you’re using game.Players.PlayerAdded:Connect(function(player) then the issue is just studio. It should work fine in the game. Sometimes your server/client scripts start a bit after your client joins the game. It only happens when testing with play solo locally.

or if it’s still an issue, you can also scan through players.

function playerAdded(player)
-- do stuff
end

game.Players.PlayerAdded:Connect(function(playerAdded)
for _, player in pairs(game.Players:GetPlayers()) do
   spawn(function() playerAdded(player) end)
end

Using CharacterAdded should’ve fixed the issue completely. There’s no need to use CharacterAppearanceLoaded since the folders are parented to the character, which isn’t relevant to accessories that might load much later (it should only be used for stuff that interacts with accessories). If the instances after the folders exist aren’t created there is an error or you aren’t providing enough information for us to help you solve your problem.

EDIT: The issue is likely that the instances parented to the folders attempt to index the folders before they actually exist.

That’s exactly how I defined it, I know I can easily do a check after and see if the folder exist, then create the folder there but It just sometimes doesn’t want to create at the beginning. I’ll try the spawn for loop and the spawn function you sent right now.

I’m a bit confused about the question, are you trying to create an instance for the character or for the player? (is the script ran upon player join or upon character exist)

If upon character exists, could you make a print check whenever a character exists (and the rest of your stuff under the print)? See if it prints or not?

That’s what I thought as well. But the beginning is just DataStore. After then Character gets added, Folder is created, and it’s just parented to the player’s character. I do believe what you said on your edit might be correct.

Creating a instance for the character, I defined the character function after the player function. I do make a print, sometimes it creates, sometimes it doesn’t. I might give a go at CharacterAdded one last time.

When you fetch the data, do you yield by any chance? It could take longer sometimes so the folders are created after the character is parented to workspace. In this case, using something like WaitForChild will probably fix it but you might have to refractor some of the code if it’s intended to run as if there was no yielding. For instance, if I waited for the folders before connecting an event, the event won’t fire until after the folders exist.

Can you give us your full script? Even if the character didn’t load yet an error could happen and the folders won’t be parented. You don’t seem to be getting an error, just the folders not being parented.

This. I done this and ran a Local Server with 5 test players 10 times. It works now. Thank you.