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

I'm trying to make a randomized StarterCharacter spawn?

I have a successful character randomizer between two characters, but I'm trying to make up to 5 characters, but since my brain is smooth, I dont know how to add to my current script:

while wait(0.5) do local CharRound = math.random(1,2)

if CharRound == 1 then
	game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
	game.StarterPlayer.Characters.Boy.StarterCharacter:Clone().Parent = game.StarterPlayer
	print("Character Two selected.")
	
elseif CharRound == 2 then
		game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
		game.StarterPlayer.Characters.Girl.StarterCharacter:Clone().Parent = game.StarterPlayer
	print("Character One selected.")
end

end

Anything help. thanks :)

1 comment

0

[EDIT] THE [While wait(0.5) do local Charround - math.random(1,2)] AND [end] ARE SUPPOSED TO BE IN THE SCRIPT

1 answer

firstly put all your characters into one folder or model and no need to name then all "StarterCharacter"

local characters = (The path to the instance containing your characters)

local starterPlayer = game.StarterPlayer





while wait(0.5) do
	local chosen_index = math.random(1,5)
	local chosen_char = characters:GetChildren()[chosen_index]:Clone()
	chosen_char.Name = "StarterCharacter"
	
	if starterPlayer:FindFirstChild("StarterCharacter") then
		starterPlayer.StarterCharacter:Destroy()
	end
		chosen_char.Parent = starterPlayer
		
end


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