Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

In sequence instead of random flashing?

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

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

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.

1 comment

0

i dont think that's what he's trying to do

This discussion is preserved as it was. New answers, comments, and votes are closed.