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

Problem with random numbers in arrays?

Asked by
Mystdar 352 Moderation Voter
9 years ago

Firstly this is a different error from my last question, it is unrelated from my last question other than the fact it is the same script, further down the script this time, I have encountered a different error.

This is a normal script in the Workspace

Colours = {BrickColor.new("Institutional white"), BrickColor.new("Pastel yellow"), BrickColor.new("Sand red")}

function Bandits()
    for i = 1, 3 do
        Bandit = game.Lighting.Bandit:Clone()
        Bandit.Parent = game.Workspace
        Bandit.Name = "Bandit"..i
        for index, Child in ipairs(Bandit:GetChildren()) do
            Choice = math.random(1, 3) -- Here is where it is generated
            print (Choice)
            if Child.Name == "Left Arm" or Child.Name == "Right Arm" or Child.Name == "Head" then
                Child.BrickColor = Colours[Choice] -- Here is where the change takes place
            end
        end
        Bandit:MoveTo(game.Workspace["Spawn_Position"..(i)].Position)
    end
end

My problem is it is meant to make 3 bandits where each bandit has a random chance to have a different skin tone, the problem is it makes a random colour for each limb so they may have an institutional white left arm, but a sand red head and a pastel yellow right arm, there is no help in the output. I believe it is because it is generating a random number for each limb, not for each bandit, thanks.

Answer this question