Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to randomise Character using Starter Character or Any other ideas?

So I am messing around with an idea I had and I want to make it so every time you die your character changes between the four characters that I have in RepStorage.

I have a basic idea of I have to use Math.Random and put it into StarterPlayer and name it starter Character but I am not too great using Math.Random so I am not sure what I would do here or where to put the scripts.

If someone could help me out that'd be great!

1 answer

✓ Accepted answer

I was about to answer this when cloudflare got hit, but anyway, it's given me time to think about this, and I believe the best way to do it is as follows:

So in rep storage, you have 4 character models, all named "StarterCharacter", keep them in a folder named something like Characters. Then in your script, do something like this:

(this is mostly pseudocode, you will have to polish it to your specifications)

local chars = RepStorage.Characters:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		StarterPlayer.StarterCharacter:Destroy()
		chars[math.random(1,4)]:Clone().Parent = StarterPlayer
	end
end

So you get a table of all the characters using getchildren, and then when a player's character loads in, you destroy the old one and get a new model in so that it preps it for the next time the character loads in. This way you don't need to handle anything with loading the character in yourself.

3 comments

0

Where do you put the script?

0

Thanks (:

0

Jonny, I never provided a script, that is only pseudocode, anyway, where you put your scripts should never change. Always keep them in server scripts. It's there for a reason.

This discussion is preserved as it was. New answers, comments, and votes are closed.