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

How to make this function affect all selected parts at once?

Asked by 5 years ago
Edited 5 years ago
for i,v in pairs(light:GetChildren()) do
                local start = v.MainLight.Color
                 local End = selcolor

        for i = 0,1,.1 do
            wait()
            local color = start:lerp(End,i)
            v.BrickColor = BrickColor.new(color)
            v.Color = color
        end

    end

That's my code and it works but I want all the parts to change colour at the same time, not one after the other.

https://gyazo.com/40be1e6c8d5c7225cb90039d32c8a2cb

I don't want to union them since my system to change the colours allows you to change each individual part's colour or all of them at once.

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
5 years ago

A for i loop will stop any code from running below it until it is finished reaching it's goal. To stop this, place the loop inside a spawn function:

for i,v in pairs(light:GetChildren()) do
                local start = v.MainLight.Color
                 local End = selcolor
    spawn(function()
            for i = 0,1,.1 do
                wait()
                local color = start:lerp(End,i)
                v.BrickColor = BrickColor.new(color)
                v.Color = color
            end
    end)
    end

Ad

Answer this question