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

How to select a random character for appearance override?

Asked by 6 years ago

Hello, I have created 4 player models hat I want to act as "Default" characters for my game. To try and do this, I set up this script:

local characters
local clone

function onPlayerEntered(player)
    characters = math.random(4)
        if characters == 1 then
        clone = script.StarterCharacter1:Clone()
        clone.Name = "StarterCharacter"
        clone.Parent = game.StarterPlayer
    elseif characters == 2 then
        clone = script.StarterCharacter2:Clone()
        clone.Name = "StarterCharacter"
        clone.Parent = game.StarterPlayer
    elseif characters == 3 then
        clone = script.StarterCharacter3:Clone()
        clone.Name = "StarterCharacter"
        clone.Parent = game.StarterPlayer
    elseif characters == 4 then
        clone = script.StarterCharacter4:Clone()
        clone.Name = "StarterCharacter"
        clone.Parent = game.StarterPlayer
    end

    end

    game.Players.PlayerAdded:connect(onPlayerEntered)

The problem is that every player has the same character, I want there to be a mix of the 4 characters I have created

0
This is a very simple error with your scipt. the characters = math.random(4) is wrong and should be characters = math.random(1,4) popgoesme700 113 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

You can use math.randomseed(tick()) in the first line of your script to generate new random seed every time

Also, use math.random(1,4) to generate number from 1 to 4

0
Good job. Exactly what OP wanted popgoesme700 113 — 6y
Ad

Answer this question