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

In sequence instead of random flashing?

Asked by 5 years ago

Instead of my lights flashing at random intervals, they go on an off in sequence. How come?

local Time = 5
local descendants = script.Parent.Lights:GetDescendants()

if Time == 5 then
    repeat
        wait(math.random(1,3))
        for index, descendant in pairs(descendants) do
            if descendant:IsA("PointLight") then
                descendant.Brightness = .1
                wait(.3)
                descendant.Brightness = 1
            end
        end
        Time = Time + 1
    until Time == 5
end

2 answers

Log in to vote
1
Answered by 5 years ago

It's most likely because the randomseed is picking the same number each time. Try this:

local Time = 5
local descendants = script.Parent.Lights:GetDescendants()

if Time == 5 then
    repeat
    math.randomseed(tick()) -- sets the randomseed to tick(), ensuring a different randomisation every repeat
        wait(math.random(1,3))
        for index, descendant in pairs(descendants) do
            if descendant:IsA("PointLight") then
                descendant.Brightness = .1
                wait(.3)
                descendant.Brightness = 1
            end
        end
        Time = Time + 1
    until Time == 5
end
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Your script is changing all of the lights' PointLight Brightness at the same time, rather than randomizing which ones are set off, you can add another random sequence down into the table index like so:

local Time = 5
local descendants = script.Parent.Lights:GetDescendants()

if Time == 5 then
    repeat
    local timer = math.random(1,3)
        wait(timer)
        for index, descendant in pairs(descendants) do
        local randomsequence = math.random(1,2)
            if descendant:IsA("PointLight") and randomsequence == 1 then
                descendant.Brightness = .1
                wait(.3)
                descendant.Brightness = 1
            end
        end
        Time = Time + 1
    until Time == 5
end

This way, anytime a light is called in the function, it will either stay on or flicker. However, if you want the lights to flicker together you'd have to directly define them in the function instead of using a table.

0
i dont think that's what he's trying to do theking48989987 2147 — 5y

Answer this question