Loading player when map loads not working

So I am trying to load the player when the map changes, when the map changes it deletes the player and respawns it. For some reason roblox thinks the character exists but its not appearing! Please help me fix this.

Are you using this in a local script? I noticed the “plr” variable, and it is not defined in that event.

If it’s a server script, avoid defining multiple events for each player. Just loop through the players every time it changes.

Again, LoadCharacter only works in server, and no need to set the character parent!

Adding to what @RafaelFixe1 said, you also need to set the cframe of the player’s character after you load it.

Its not even appearing in the workspace, its not a local script because right above that code its in a game.players.playeradded function

can you post the entire code the snippet provided is very vague

I will once roblox is back up lol

1 Like

this is the full script

Hey dude, uhm the current code logic you have shouldn’t have flaws in its performance. It’s probably an issue with how this script is interacting with the system you set it up with.

To debug, I suggest adding a print statement on line 5 (right after the MapLoaded Value changes) to see when this event fires. You want the value to fire true when the map is loaded, and stay true until you’re done with the map.

print('Fired with value: '..tostring(workspace.ServerSettings.MapLoaded.Value))

If this part isn’t getting printed, then you’re never getting to the code to spawn the player. If you are getting this printed out, then make sure your if statements match with the possible values they could be. For example true ~= ‘true’, so make sure MapLoaded is a BoolValue.

One other thing to note, after a character has been loaded, player.Character will always exist.

Place your code in code blocks visit here About the Scripting Support category to see how to do that.

The map gets added, I see it in the workspace. The issue is the player. The player isnt being added to the workspace yet when I print the localplayers characters name the character isnt nill. Its super strange. I am going to try what greatgavin said