Hi, so I have a customization screen where players can change the looks of their avatars. Anyways, I have a CharactedAdded() function that waits for the character to load and then executes code below it. But for some reason my CharacterAdded() will not fire for 50% of the time in Play Solo mode which is actually literally infuriating. Does anyone know the reason for this and how to fix it- aka make CharacterAdded() fire instead of doing nothing? Here is a bit of my code to help.
you don’t need to wait for the character inside the of the CharacterAdded function, the CharacterAdded function gets called when the character is loaded.
I know that is supposed to make sense, but the wait inside makes it run with a 40% better success rate to fire. It’s weird but i’ve tested it, it actually helps the code run which in most cases does NOT for goodness knows why.
I think it happens because the game takes longer to load the map than the character, so the character loads first.
Add Player:LoadCharacter() above the function and disable CharacterAutoLoads.
The rest of the code is either wait lines or functions that fire properly when the script wants to work. Also, setting CharacterAutoSpawn() to false and using Player:LoadCharacter() just makes me spawn in the middle of the blue sky box with nothing to see. Am I doing it wrong? Thanks.
Tried this but it still doesn’t fire the code 100% of the time. At first it was okay, but then it stopped making it work. Thanks though. EDIT: NVM, I think it works but I have no idea how to access player.
I have no idea what (player,character) variable you’re talking about. If you’re talking about event arguments (the argument in your connected function), then those will absolutely never be nil, nor inaccessible.
Make sure you check when you’re connecting the player added function. A simple print before the connecting line is a sure-fire way to tell if it’s connected or not.
It’s this: local function CharacterAdded(char, Player) I added Player but it doesn’t even access it- it’s nil. Also I have more test print code in there than a minefield… But it works now, TY.
No, it works fine now but the code you gave me didn’t include player in CharacterAdded() so I decided to send player as an argument into the parameters for CharacterAdded() but it came up as nil, so I just used GetPlayerFromCharacter() and it works like a charm now. The reason it didn’t execute code before was because I had a line of print to test if player was successfully transferred but it wasn’t so it stopped the code. So then I just used GetPlayerFromCharacter() and it works now perfectly. Thank you.
Yeah typically you would have to adjust generic code to suit your needs. All you’d have to do in this case is to hookup the CharacterAdded function as an anonymous function in the PlayerAdded function and then pass the player argument into CharacterAdded.
Typically I’d consider using GetPlayerFromCharacter in this case bad practice since you already have the player value at hand here (you need the player to get the character). But regardless of that, it sounds like you got it working.