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

Why do these change color at the same time even though I have a wait?

Asked by
LawlR 182
6 years ago
Edited 6 years ago
local s1 = script.Parent.Spawn1
local s2 = script.Parent.Spawns2:GetChildren()

local loop = coroutine.create(function()
    while true do
        wait(.4)
        s1.BrickColor = BrickColor.Random()
    end
end)
coroutine.resume(loop)
wait(.4)
local loop2 = coroutine.create(function()
    while true do
        wait(.4)
        for i,v in pairs(s2) do
            v.BrickColor = s1.BrickColor
        end
    end
end)
coroutine.resume(loop2)

The second set of spawns are meant to wait .4 seconds before they change but they change right when the first spawn changes. Why?

1 answer

Log in to vote
0
Answered by 6 years ago
local loop2 = coroutine.create(function()
    while true do
        for i,v in pairs(s2) do
        wait(0.4)
            v.BrickColor = s1.BrickColor
        end
    wait() -- make sure that the loop doesn't crash the script
    end
end)
0
That changes one of the two spawns at a different time than the other spawn. LawlR 182 — 6y
Ad

Answer this question