Changing a Player's Character

I have a game where the character instantly gets changed to another rig, and I keep trying to reference Player.Character, and it comes back nil, and I can’t figure out why, and the reason why I can’t simply just have the starter character be the rig I auto change them to is because the game actually uses 2 characters, and rather then just teleporting the character around, it actually changes the character.

so how would I reference the character after it’s been swapped? because I’m completely baffled as to what is going on right now. any help is much appreciated :slight_smile:

1 Like

so how would I reference the character after it’s been swapped? because I’m completely baffled as to what is going on right now. any help is much appreciated

You should be able to access it with Player.Character, you’ll need to define it after you set the player’s character to the rig.

I found this Video helpful.

1 Like

the weird thing is that I reference it every time I fire a function which is checking where the character is, and it still comes out nil

Can we see your script please.

Ok, a few questions:

  1. Do you swap the character from a script or a local script?
  2. Is there a Humanoid object in the other character.

I’m swapping it from a server script, and yes there is a humanoid in both characters.

Is the character positioned exactly where the old character was, and parented to workspace?

Create a local variable for the :Clone part(), parent it, then access it via the variable.

1 Like

I’m using this to swap, the event is just so I can fire it from the client too.

	local character = player.Character
	if character.Name == "Player1" then
		local clone1 = game.Workspace.Player1:Clone()
		clone1.Parent = game.Workspace
		player.Character = game.Workspace.Player2
	elseif character.Name == "Player2" then	
		local clone2 = game.Workspace.Player2:Clone()
		clone2.Parent = game.Workspace
		player.Character = game.Workspace.Player1
	elseif character.Name ~= "Player1" and character.Name ~= "Player2" then
		player.Character = game.Workspace.Player1

I could combine my current script and the one that swaps them I guess, and that would then give me the variable, or I could use an object value, which would probably be easier.

I don’t really understanding why you are cloning one character, then trying to parent it the other one.
Also, change the current character name to the player name, so it won’t be picked up by the script again.
Otherwise, every time, players will switch the same character between each other :sweat_smile:

its what had to be done, because if not it would glitch back to the original character it swaps you to. also this is a single player game

Clone the same character, and just rename it so it won’t be picked up again.

it gets destroyed, and the players won’t swap between the same ones as its gonna be a single player game. also I knew it would be an issue with multiple people as my play tests are sometimes crashed by my brother messing up the movement

Ah, that explains it.
When you switch characters, do you want the character to replace the current in the same location? Or a different one?
Sometimes, the character just falls of/disappears if isn’t positioned well.
It doesn’t teleport to the original character on default.

it swaps just fine, the issue is I can’t reference the character without it coming out nil

Previous post, not the most effective solution, but it works. Not sure if this is what you were asking for.

see I’m not morphing the character, I’m actually changing it to an entirely deferent rig, and I have it working, but the issue is that I can’t reference the character without it being nil.

Is the property Archivable of the character set to true?

Archivable off disables :Clone()