Trouble getting custom characters working on individual players

Hello! This is my first time using the dev forum so I apologize if I do something wrong

Im trying to get each player to have a custom character, but all players get the same character

(Console prints out type of character and character variation, but as seen in video both players get the same variation)

I have not been able to find solutions for this problem on dev hub or YouTube, and I have no idea why its happening

I will be happy to provide any more code snippets needed, as well as any other information needed to solve this problem

local newChar = chosen:Clone()
newChar.Name = ("StarterCharacter")
newChar.Parent = game.StarterPlayer
newChar.PrimaryPart = newChar.HumanoidRootPart
		
plr:LoadCharacter(newChar)

Here is the code for the character loader

1 Like

what is chosen? It’s most likely that chosen is the same every time you call it. I suggest making it a function that chooses a random character rather than having it be a predefined variable as it will remain the same each time.

local options = game.ServerStorage.Characters:WaitForChild(plr.plrStats.race.Value):GetChildren()
local chosen = options[math.random(1,#options)]

This is what chooses the random character

image

This is the server storage for the preset characters

So, you see how you only define chosen once? that’s why its the same everytime. What you’ll need to do is have either a function or multiple chosen, I recommend the former.
Example;

local function GetChar()
local Chosen = options[math.random(1,#options)] -- gets a random character
return Chosen
end

local newChar = GetChar():Clone()
newChar.Name = ("StarterCharacter")
newChar.Parent = game.StarterPlayer
newChar.PrimaryPart = newChar.HumanoidRootPart
		
plr:LoadCharacter(newChar)

I would also like the mention it is in a normal script, not a localscript

image

Result:

I’m not sure then. I’ll need you to post the majority of your script that is handling this. Else it’s harder for me to tell what kind of indexing you’re doing for the players.

1 Like

I will most likely have to delete this post later, since i am posting the script

--code was here

Organizing your code here would go a long way but it’s not my job to criticize. I suggest you add multiple print statements to see where it’s going wrong else I’m not sure by reading it. Or it could be because you are parenting the character to StarterPlayer making everyone get it.

1 Like

What would be the alternative to parenting it to the starter player

Aren’t you already doing

plr:LoadCharacter(newChar)

?
Shouldn’t this already be giving them the char that you selected?

1 Like

For some reason it just loads the normal character

I will be tinkering with this for the next few hours, let me know if you have any ideas

Alright no problem, I’ll let you know if I figure something out to help. Also be sure to use print statements :+1:

1 Like

I have figured it out!

local newChar = GetChar(plr):Clone()
plr.plrStats.charName.Value = newChar.Name
newChar.Name = plr.Name
newChar.PrimaryPart = newChar.HumanoidRootPart
plr.Character = newChar

newChar.Humanoid.MaxHealth = plr.plrStats.health.Value
newChar.Humanoid.Health = plr.plrStats.health.Value
		
newChar.Parent = game.Workspace

One of the issues is that i was setting the new character’s parent to starter player, meaning it would effect all players. And then I tried parenting it to workspace, but doing it before you set plr.character doesn’t work. also, using LoadCharacter() will load either the players default character, or the starter character if there is one, but using this solution is not needed

game.Players.CharacterAutoLoads = false

I also put this at the top of the script to stop the normal character from loading