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

How would I make it so that the order of something is randomized?

Asked by
B3blx 5
9 years ago

Ok,Say there were 4 bricks in a model - A,B,C,D

I want them to change colour, then revert to the previous colour one at a time, but in a randomized fashion. How would I make it so that the order they change colours in is randomized?

1 answer

Log in to vote
1
Answered by 9 years ago

You can use math.random().

local children = model:GetChildren()

while wait(time) do -- put 'time' to how many seconds it takes to choose the next part
    local choosen = children[math.random(1,#children)] -- math.random() chooses a number from 1 to the number of children, which is 4 in your case
    local prevColor = choosen.BrickColor -- we store the previous color of the part
    choosen.BrickColor = BrickColor.new(newcolor) -- put newcolor to a color that the part changes to. if you want to put a random color, change this to BrickColor:random()
    wait(time) -- put 'time' to how many seconds it takes for part to return to the previous color
    choosen.BrickColor = prevColor
end
0
That's the way to use it. TheBigCoder 25 — 9y
Ad

Answer this question