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

How would I do this script in a more efficient way?

Asked by 8 years ago

I currently have it set with all the parts numbered 1-110. Rather than going like this

game.Workspace["1"].BrickColor = BrickColor.random()
wait(.08)
game.Workspace["2"].BrickColor = BrickColor.random()
wait(.08)
game.Workspace["3"].BrickColor = BrickColor.random()
wait(.08)

Any way to do this, but much easier rather than one line for each part?

0
Keep in mind, this is simply a glimpse of my script. It will not work, but you just need to see this part. Ethan_Waike 156 — 8y
0
I edit my answer to fit your other questions EzraNehemiah_TF2 3552 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

There is! Use a for loop and repeat the process 110 times!

for i = 1,110 do
    workspace[i].BrickColor = BrickColor.Random()
    wait(0.08)
end

Hope it helps!


If it doesn't work try this one:

for i = 1,110 do
    workspace[i..""].BrickColor = BrickColor.Random()
    wait(0.08)
end


You can't do all at once, but we could make it do it really fast. First GROUP the parts

local model = workspace.Model --Model here
local tick1 = tick()

for _,part in pairs(model:GetChildren()) do
    part.BrickColor = BrickColor.Random()
end

print("It took ",,(tick1 - tick()).." seconds to change all the parts colors")
0
My only question is, how would you also do this but index all of them at the same time? Ethan_Waike 156 — 8y
0
Or, do it in a random order Ethan_Waike 156 — 8y
Ad

Answer this question