Spawn as many StarterCharacter Models

I’ve placed many “StarterCharacter” Models in the StarterPlayer class - It’s supposed to make my character spawn as one of the Models.

The problem is that I spawn every time as the same character. It’s like I have Var1, Var2, Var3, Var4 and I always spawn as Var 4 (this is only an example).

I was thinking if the StarterCharacters were constantly destroyed and pasted again from ReplicatedStorage they will change it’s order and I’ll maybe spawn as a different character every time I spawn? With a while loop. But I don’t know how to do that, I’ve tried a couple of times and it didn’t work :frowning: I’m a beginner into scripting.

Any ideas?

2 Likes

You should try inserting all the characters into a table and then choose a random one.
These should help:
https://developer.roblox.com/articles/Random-Number-Generation
https://developer.roblox.com/en-us/articles/Table
For more randomness you can do:

math.randomseed(tick())
3 Likes

You can make an array of all the characters available to spawn with, then pick a random index within the array.

local chars = {Var1, Var2, Var3, Var4}

local charIndex = math.random(1,#chars)

local selectedchar = chars[charIndex] -- will be one randomly chosen char from the array

Hope this helps!

2 Likes

There’s plenty of resources out there, for example:

2 Likes

I recommend to use HumanioidDescriptions and not StarterCharacters if your characters are r15
Links:

https://developer.roblox.com/en-us/api-reference/class/HumanoidDescription

https://developer.roblox.com/en-us/articles/humanoiddescription-system

2 Likes

StarterCharacter isn’t meant to be used this way. You’re only supposed to have one StarterCharacter which you don’t modify at any point in your game. If you find yourself stuck with cases like this, you need to change the overall idea in how you’re going to transform characters into new ones.

Such solutions can be found in the post above mine.

1 Like