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

How to make it so that a loop executes every so seconds and doesn't wait for previous loop?

Asked by 8 years ago

I'm trying this loop that executes a function that makes a brick invisible

local parts = script.Parent:GetChildren()


local function blink(part)
    if part:IsA("BasePart") then
        for transparency = 0, 1, 0.2 do
            part.Transparency = part.Transparency + 0.2
            if part.Transparency == 1 then
                part.CanCollide = false
                wait(2)
                part.Transparency = 0
                part.CanCollide = true
                break
            end
            wait(1)
        end
    end
end

while true do
    for i, v in ipairs(parts) do
        blink(v)
    end
end

It does go through every child in parts but it only works on one brick each time. I would like to know how to make a brick start turning invisible every so seconds instead of having it wait until the part is done executing the function

1 answer

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago

You will have to use coroutines

Info On Coroutine n' Examples

Ad

Answer this question