for i,v in pairs(script.Parent:GetChildren()) do if v:IsA("Part")then v.BrickColor=BrickColor.Random() wait(1) end end
Just a simple script to change a bunch of bricks with a 1 second delay between them. My problem is that it goes in the same order every time. What method should I go about in randomizing this? Thank you!
Here's a Shuffle function that I've found quite useful:
function Shuffle(list) for i = 1, #list-1 do local index = math.random(i, #list) list[i], list[index] = list[index], list[i] end end
Shuffle the children before iterating over it and it'll be different every time. Either make sure to use math.randomseed(tick())
in one place in one script or change the code to use Random.