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.
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)
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.