I do not want :GetChildren() to return parts in the order i created them. I want it to be fully random
Im trying to make a whole ceiling of lights turn off one by one in a random order but its instead turning them off in the order i created the lights in which does not look good at all
this is my code
for _,v in pairs(workspace.Lights[Zone]:GetChildren()) do
if State then
v.Light.Color = LightOnColor
v.Light.SurfaceLight.Enabled = true
else
v.Light.Color = LightOffColor
v.Light.SurfaceLight.Enabled = false
end
wait()
end
Thanks
that intended behavior
You can mix out table using table.sort or make own alghoritm.
table.sort provides a callback function as argument that you can use to manipulate values.
Also using pairs() is not needed as since its an outdated feature
Doing wait() is also completelly unneed and incase you do use it then use task.wait as a replacement
etc:
local function callback(a:Instance,b:Instance):boolean
return math.random(0,1)==1
end
local t = workspace.Lights[Zone]:GetChildren()
table.sort(t,callback)
for _,v in t do
if State then
v.Light.Color = LightOnColor
v.Light.SurfaceLight.Enabled = true
else
v.Light.Color = LightOffColor
v.Light.SurfaceLight.Enabled = false
end
task.wait()
end
local lights = workspace.Lights[Zone]:GetChildren()
Random.new():Shuffle(lights)
for _,v in lights do
if State then
v.Light.Color = LightOnColor
v.Light.SurfaceLight.Enabled = true
else
v.Light.Color = LightOffColor
v.Light.SurfaceLight.Enabled = false
end
task.wait()
end
1 Like
erm actually its a Random:Shuffle()
Get out-
Yeah its a method for some reason? 
Edit:
Its a part of class so its
Random.new():Shuffle() ig
1 Like
My bad. I thought of it as a “static” method in my brain. Too much java. 
Ah, that makes much more sense.
1 Like