Light beam scripting Help

So I have a script that is supposed to make some light beams brightness go from 8.75 to 0 back to 8.75 rapidly and my script looks like this

[Link to script]

The issue with the script is that inside of
script.Parent.ClickDetector.MouseClick:Connect(function()

It runs wait(0.6)
Lights(Lights1, 8.75)
wait(1)
Lights(Lights1, 0)

Or something like that but just stops there even though inside the output screen it perfectly runs through all the lines but no changed happen except for the beginning two.

Output: Beam Beam Beam Beam Beam Beam Beam Beam - Server - Script:24

Does anyone know how I can fix this?

If this isnt a good enough explanation I can just record it if needed.

can you record so i can know what’s wrong?

Reading your code, I found the issue.

v.Brightness = tonumber(v) or 1

v (as in the parameter of the function) is overridden by v in the for loop, and therefore the code only sets the brightness to 1, as tonumber(Instance) is always equal to nil.

Rewrite as follows:

local Lights1 = {}
for i, v in pairs(workspace["Marmaliser V4"].Flasher_Leg.Lights1:GetDescendants()) do
	if v:IsA('Beam') then table.insert(Lights1, v)
	end
end

function Lights(TAB, bright)
	for i, v in pairs(TAB or nil) do
		v.Brightness = tonumber(bright) or 1
	end
end

script.Parent.ClickDetector.MouseClick:Connect(function()
	wait(0.6)
	Lights(Lights1, 8.75)
	wait(1)
	Lights(Lights1, 0)
	wait(1)
	Lights(Lights1, 8.75)
	wait(1)
	Lights(Lights1, 0)
	wait(1)
	Lights(Lights1, 8.75)
	print(table.unpack(Lights1))
end)

Oh yeah I remember changing it to 8.75 but even with 1 it doesn’t work.

Have you tried with the code I sent?

No because I thought you just changed a number to 1 but then saw you changed other things so I might test it now holdon

Woah it actually works! Thanks!

I do got one more question though. I got spheres where it glows white for the lights and inside the model it goes sphere.001 sphere.002 how could I easily make a script that isn’t cluttered but changes the brick color from white to black to match the light beam turning on and off? Should I rename all the spheres to just sphere and make another table but have it have something to do with the brick color?

You can make another table as you did with the lights. Then, integrate the color change into the Lights function. If the second parameter (bright) is greater than 0, then turn it white. Otherwise, turn it black.

local Lights_1 = {}

for i, v in pairs(workspace[“Marmaliser V4”].Flasher_Leg.Lights_2:GetDescendants()) do

if v:IsA(“Part”) then table.Insert(Lights_1, v)

end

function Lights(TAB, bright)

for i, v in pairs(TAB or nil) do

v.Brightness = tonumber(bright) or 1

end

end

I am no great at coding so how do I incorporate it to make it go black white black white

It was meant to say Lights_2 aswell in the .insert(lights_1, v) area so don’t mind that

Or Lights_1 I mean. I think I overcomplicated that lol