Help with CustomCharacter script

So I’ve created a custom character and want to change the players character to that one mid-game. I have in fact successfully done that but I don’t think I’ve done it the best way.
Here is the script:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player)
	Player.Character:Destroy()
	local NewChar = game.ServerStorage.CustomCharacters.PlayerMonster:Clone()
	local Anims = NewChar.Anims:Clone() -- Where the animations are held
	Anims.Parent = game.StarterPlayer.StarterCharacterScripts -- Since they are deleted upon character loading I did this
	NewChar.Parent = game.StarterPlayer
	NewChar.Name = "StarterCharacter"
	Player:LoadCharacter()
	Anims.Parent = Player.Character -- Puts the Animations back into the Character
	NewChar:Destroy()
end)

It goes really fast to the point where you can’t even see it in the explorer when it happens but is this the right way? I read many topics about it and they all failed to work.

You aren’t using StarterCharacter properly. It is not meant to be dynamically switched in and out of, it is supposed to be a static asset in StarterPlayer that changes how rigs are constructed by default. If you want to change a player’s character model, use Player.Character = Model. From there, any other configurations that may be applicable afterward (e.g. network ownership) can be used.

1 Like

Add a CharacterAdded function so it waits for the character to load then it destroys it.

I’ve tried using Player.Character = Model, it just kills me then I respawn as my old character.

Add a Character Added function then it will spawn you as the character you want, since the code will run whenever you character is added to the workspace.

I’ve also tried that and it just keeps respawning me over and over and over again.

Who said that static things cannot be changed? I think it’s actually a good way to utilize the StarterPlayer functionality. It works very well with :LoadCharacter() But for dynamically changing the model on the fly you cannot reload your character… you must clone all the parts that you want and then destroy and replace them or you could probably use the humanoid method ReplaceBodyPartR15(BodyPartR15, instance)

Reference:
https://developer.roblox.com/en-us/api-reference/function/Humanoid/ReplaceBodyPartR15

1 Like

Are you sure that doesn’t work? I made my custom character once (it was R15), I just cloned the custom character, renamed it to the player’s name, moved it to the place of the old character, and destroyed the player character and then set it to the new one. It worked perfectly fine for me. When I accidentally did that from a local script (I shouldn’t have done it from there), it killed me.

That depends on what “static” item is in reference here. StarterCharacter’s intended purpose is to change the way that all characters are constructed, not for it to be quickly swapped in and out for new players. That’s a gross misuse of StarterCharacter, disregarding other problems like hitting edge cases (more than one character changes, for example) due to said improper use of it.

The proper way to change one player’s character at run time, if you need to change the model in the first place, is to change what Player.Character is. StarterCharacter is if you want to wholly change how characters are constructed.

Please do be mindful that one of the questions is “is this the right way”, which it isn’t. Just because things work, doesn’t mean they should be used. Changing a single player’s character via StarterCharacter is not its intended use and it’s not a good way to utilise it at all.