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

How to make blocks start their script simultaneously?

Asked by 7 years ago

I don't know if I already have the answer for this myself, but even if I do I'm not sure how to execute the rest of it. I want all my blocks to be in sync when the server starts.

The original code in the blocks was:

while true do
    script.Parent.BrickColor = BrickColor.new("Electric blue")
    wait(0.5)
    script.Parent.BrickColor = BrickColor.new("Lapis")
    wait(0.5)
end

Basically this code was just copy and pasted into several other bricks, although some with different colors, but I noticed it wasn't in sync when changing. So, I was personally kind of thinking of adding a ServerScript that waited like 0.2 seconds then ran print("Start!").

Off of that, I was going to add to the original. I was planning to make it start when the word was printed. Don't know how to script it that way though.

1 answer

Log in to vote
0
Answered by 7 years ago

It would probably be best to use a single script for all the parts. Let's say you have all your parts in a model/folder in workspace called "Bricks".

local bricks = workspace:WaitForChild("Bricks"):GetChildren()

Here we store the parts in an array called "bricks".

To do something to all parts in this array, we're going to use a for loop.

for _, part in pairs(bricks) do
    part.BrickColor = BrickColor.new("Electric blue")
end

Here we change the BrickColor of every part stored in the array.

We can easily put this together with a while loop.

local bricks = workspace:WaitForChild("Bricks"):GetChildren()

while true do
    for _, part in pairs(bricks) do
        part.BrickColor = BrickColor.new("Electric blue")
    end
    wait(0.5)
    for _, part in pairs(bricks) do
        part.BrickColor = BrickColor.new("Lapis")
    end
    wait(0.5)
end
Ad

Answer this question