Efficient method if assigning custom character based on leaderstat value

I want my game to assign a player’s character to either their preferred character, which is saved as a string value to their player, or the default character for their level of points.

I know I can set starter character and add my own Animate localscript to the startercharacter scripts, but what if I want to change it dynamically?

Is there something like starter character for every individual player that i can change?

1 Like

You can change the player’s Character property. You can insert the model of the chosen character and you’ll have to change the CameraSubject to the new character:

-- On server (in a script when player spawns) 
local model = workspace.Model
player. Character = model

-- On client (in a local script when player respawns) 
camera.CameraSubject = player. Character. Humanoid

I’m not sure if this is the best way

1 Like

wait so character is a property? i thought it was a reference to their char in the workspace which may or may not exist

It is a property. Every property has a data type. WalkSpeed is a number. Name is a string. Player.Character can be any Instance.

So if I am understanding correctly,

when I write A = Player.Character

A is = to the players character in the workspace

But when I write Player.Character = B

Im replacing the default character property of the player with model B, and changes only get applied when I call :LoadCharacter() on the player?

Can i stick the animate script inside the model and it will work? If so, Im also wondering what the best way to stop roblox from putting putting their animate script in is.

1 Like

Not if you’ve previously set Player.Character to be something different. But by default, yes.

Not quite. When you assign B to Player.Character, THAT IS WHAT PLAYER.CHARACTER IS. Any script that later looks up Player.Character will get a reference to B, not the old character. The default ControlScript and CameraScript look up Player.Character at some point. If they’re not set up to listen for changes to the property, then they probably won’t react correctly when you set Player.Character to B. You’ll have to try it out and see what happens.

Player:LoadCharacter creates a new character based on StarterPlayer.StarterCharacter (or the default character if it doesn’t exist), as well as the player’s avatar appearance, then puts the newly created character into workspace and positions it at a SpawnLocation, and sets Player.Character to the newly created character.

There’s nothing special about the Player’s character, it’s just a Model like any other. Some of the default systems interact with the Player.Character property, but you can override all of them.

If you put a LocalScript called “Animate” inside StarterPlayer.StarterCharacterScripts, then it will replace the default animation script. Save with the Health and Sound LocalScripts.

1 Like

B = some custom character model in serverstorage with an animation script

If I do player.Character = B while said player is already running around in game, does B get parented to workspace, and does their client start running any scripts like the animation script inside B?

Im thinking of putting a dummy script named Animate inside startercharacterscripts and then having another script called “ActualAnimate” that handles animations. This script goes in my custom character models so that I can swap it easily

1 Like

Don’t use StarterCharacter or anything under StarterPlayer if you intend to incorporate dynamic switching for characters and scripts. That container is if you have hardset overrides for character behaviour that all players should abide by.

What kind of character changes are you making that require you to change the character? At present, working with Humanoids is hacky and annoying. If you are just changing clothing and general character assets, use HumanoidDescriptions and store assets that don’t fit in one in a storage service. If you actually need to change the construct of a rig (e.g. Humanoid → Animal), then it’s worth continuing to look at changing the actual Character itself.

2 Likes

Id like to be able to change the whole charscter itself since it seems easy for me to do, but if thats very hacky then maybe I shouldnt.

I COULD downgrade my plan to just changing the mesh of every part on one common rig, but I dont know how to make it so that every player gets the correct set of meshes for their character’s body parts every time they load.

Ive never used humanoid desc before. Does it work with custom rigs? I have an animal rig im trying to dynamically change.