Flickering light not working

I am trying to make a flickering light, but it is not working. The code is running, it has found the parts, and it can change the material of something, but the light will not change brightness, range, or parent properties.

Output

image

Hierarchy

image

Code
lightPart = script.Parent.Parent
print(lightPart.Name)

light = script.Parent
print(light.Name)

bright = light.Brightness
print(bright)

print("Starting light flicker")

while true do
	bright = 1
	lightPart.Material = Enum.Material.Neon
	--wait(math.random(0.1, 0.5))
	wait(1)
	bright = 0.01
	lightPart.Material = Enum.Material.Glass
	--wait(math.random(0.1, 0.5))
	wait(1)
	print("loop")
end

I want the light to turn on and off, and I want the material of the lightPart to change at a random interval so it looks like flickering. I changed it to 1 second for testing.

If you want to see it in game: Hexagon Labs - Roblox

Hello FinnBotF11!
When you create a new variable (bright = light.Brightness), that variable doesn’t represent an object value, meaning that when you change it, it won’t affect the light properties, only the variable (Int Value).

Try this script:

print("Starting light flicker")

while true do
	script.Parent.Brightness = 1
	script.Parent.Parent.Material = Enum.Material.Neon
	--wait(math.random(0.1, 0.5))
	wait(1)
	script.Parent.Brightness = 0.01
	script.Parent.Parent.Material = Enum.Material.Glass
	--wait(math.random(0.1, 0.5))
	wait(1)
	print("loop")
end

Tell me if that works!

1 Like

Oh ok tysm I will try that now

EDIT: It works!