just an insight as to how i could go about it please
Character 1 is the player. Character 2 is the horse (the human is cloned on top of it, because eventually I want ANY human to clone on top). That’s my character switching system.
The only thing I did not do with my code was try to keep Character 1 alive. Obviously in this request, you want to hop between 1 and 2 and both stay alive.
To keep #2 alive, remove the Humanoid.
To keep #1 alive:
Option 1: Don’t bother! Clone Character 1, make its parent game.Workspace. Since the client never controls the clone, it does not die.
This took 5 lines of code to add a new clone:
Option 2: Save the old model! This was not as hard to do as I thought. When the character swap happens, the old model now has a parent of “nil” which is why it disappears/dies. Just set the parent to game.Workspace after the swap and it will come back.
In this example, I threw a test dummy out there (right), and just swapped bodies (remove humanoid of the target, of course, to prevent death/respawn).
2 lines.
local oldchar = char -- only new lines
local test = game.Workspace.Human --human does not have a Humanoid in it
player.Character = test
local hum = Instance.new("Humanoid")
hum.Parent = player.Character
oldchar.Parent = game.Workspace -- only new lines
None of this addresses the cleanup work required (setting new animations for new Humanoids, resetting the camera, etc) but the switch is complete.
Yes, I could see how this could be useful. But check the original request. He wants the other character to follow the main/possessed one after switching. This would have worked for a stationary character switching system, and I’m certain you can apply it here too. My opinion hasn’t changed, still not sure as to how this relates to the topic.
-
For the actual character switching to work, we’ll need to use a gui button, context action service or user input service. I’ll be using UserInputService for this. We can easily create a function for InputBegan and then check to see if our desired key is pressed.
if input.UserInputType == Enum.UserInputType.Keyboard then
local key = input.KeyCode
if key == Enum.KeyCode.thekeythatyouwant then
code here
(input being the variable in our function) -
The way I’m thinking about switching the characters is simple. We could just swap the appearances of both the characters to give the effect of them switching. You could create an array of all the accessories or just loop through them. Then clone and weld them to each character and have a separate loop to destroy the old ones. I recommend having some sort of naming system so that your script can detect which ones to destroy and which ones to keep. Here’s a post that could help you with this.
-
Finally, to make the extra character trail off the possessed character, you could just use humanoid:move() in a loop with some offset.
Thats all I could think of. This is a pretty new concept to me and of course I’m not perfect so if you have any ideas feel free to tell me them.
You can do something like:
Player.Character = CharacterA
Player.Character = CharacterB
And each time you set the .Character property of the Player to a new model you will need to set the network ownership of the characters to their appropriate owners, Server for A when you switch to B and B to the Player and vice versa.