Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I'm trying to make a randomized StarterCharacter spawn?

Asked by 3 years ago

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 :)

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

1 answer

Log in to vote
0
Answered by 3 years ago

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


Ad

Answer this question