Switching players in run-time

Hello everyone!

I am making a game in which I need the player to control a different character. Basically, when a certain event triggers, it should pick a random character and then switch the character to become it.

In the game, when you die, you possess another character model, I just need to know how to make it control the new one and switch to so that character is that new model.

Player dies > Game finds a new model within a distance > camera changes to that model and player can now use that to move.

Help is very much appreciated, thanks for reading!

If you use ApplyHumanoidDescription on the player’s humanoid, you can set their character’s appearance to that of another UserId.

This is pretty much the best solution I can come up with in regards to your issue.

local humanoid = -- humanoid of the player
local id = -- user id of the player who has the humanoid model you want to set to the player

local humanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(id)
humanoid:ApplyDescription(humanoidDescription)
1 Like

I mean that when the player dies, they physically control a different player model. Like the camera goes to a different model and then the player controls it. Like the player’s “consciousness” goes to another model.

The way I would do it, would be to do this…

  1. When you spawn in, hide the default character (put it in a room off map, or make invisible, anchor it, etc…)
  2. Find the ‘character’ you want them to control, and set their camera to it (if nobody is using it already)
  3. Have a script that takes the Core Script movement module inputs and applies them to the humanoid inside the ‘character’

There is most probably a better way to do this, but this is the approach I would take, with my limited knowledge on doing this.

2 Likes

I have already done some of this in my game, and I noticed that you should really never give the player control of a character they do not own (another player’s character) you should instead fake it with HumanoidDescriptions.

1 Like

For me, the player is a weeping angel and when they are being looked at, they get teleported to and control a weeping angel that is not being looked at. Could I effectively fake it by just setting the cframe of the player to the weeping angel model, and then delete the model? And when the players get looked at, they get cloned without humanoid and then the player gets switched?

That might work, you could try that.

We’ll how I do it is by setting the Player’s cameraSubject to the model and since the character model isn’t another player you could fork the PlayerControl scripts and edit it to your liking.

2 Likes

lol, thats what I just said in my original post, although I think you say it better XD

1 Like