Character switching

Hello devs!

So my idea is simple but i don’t quite know how to execute this.
I basicly want the player to be able to switch between their own character and another character (not neccesarily a player character) when they press Q.

I have tried looking for solutions on the Developer Forum, but most of them are outdated.

Any help is greatly appreciated!

Do you want the secondary character to have movements or just be a spectator?

Yes I want them to have movements.

As far as I know, you’ll need to work on both the client and the server to make this possible. First, you’ll set the player’s character as the new character.

local CurrentCharacter = Player.Character
Player.Character = newCharacter -- needs to be a model with a humanoid

If you want the animations of the current character to transfer to the new one, you’ll need to clone the script called “animate” from the current character.

local CurrentCharacter = Player.Character
Player.Character = newCharacter -- needs to be a model with a humanoid

local Animate = CurrentCharacter.Animate
Animate.Parent = Player.Character

Finally, on the client side, you’ll have to change the camera subject from the current camera to the humanoid of the new character.

local CurrentCamera = workspace.CurrentCamera

local function UpdateCamera(newCharacter)
CurrentCamera.CameraSubject = newCharacter.Humanoid
end

Just a correction, you don’t need to clone the animate’script, just transfer it to the new character.

The character can move but there are 2 issues right now:

1. The character has no animations.
2. The character freezes after a couple of seconds.

About the animations, to make them work in case you want to use those from the old character, you have to ensure that they have the same rigs. Otherwise, there may be issues because the animator for R6 and R15 are different.

About the character freezing, it could be an issue with the model, as during a test with an R6 dummy, I couldn’t replicate the error

I didn’t use the animation from the old character and when I was testing I was doing it with an R15 dummy instead of R6 which you used. The old character was R15 too.

Ok i just ask that you wait a moment while I investigate what’s happening with R15.

1 Like

I created a test code here with the R15 dummy, and it’s working correctly with the following code on the server.

local function UpdateCharacter(Player, newCharacter)
	local CurrentCharacter = Player.Character
	
	Player.Character = newCharacter
	CurrentCharacter.Animate.Parent = Player.Character
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		task.wait(10)
		UpdateCharacter(Player, workspace.Rig)
	end)
end)

To make the animations work, you need to transfer the ‘Animate’ from your character to the other one or use another ‘Animate’ that matches the character’s rig. If the person you’re changing the character for is a player, you can simply clone their ‘Animate’, delete the current one, and add the cloned one.

About the character freezing error, could you send a video of how it happens?

Thanks, the camera isn’t following the new character but thats an easy fix.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.