Need help with material changing lamp

So I was making a flickering lamp and I am trying to make it so the material changes to smooth plastic when it’s off. But it doesn’t change and I don’t know what I am doing wrong.

    local Light = game.Workspace.Lamp1.Part1.PointLight
    local material = game.Workspace.Lamp1.Part1.Material

    while true do
wait(0.4)
 Light.Brightness = 0
  material = Enum.Material.SmoothPlastic
wait(0.5)
Light.Brightness = 1
  material = Enum.Material.Neon
wait(0.3)
 Light.Brightness = 0
	material = Enum.Material.SmoothPlastic
wait(0.1)
	Light.Brightness = 1
 material = Enum.Material.Neon
end
1 Like

Ah yes cursed code

There’s actually a way better approach of doing this than just rather trying to implement the lines of code over and over, also you could try just getting the Part instead of having to use 2 variables?

local Part = workspace.Lamp1.Part1

while true do
    for Loop = 0.5, 0.1, -0.1 do
        Part1.Brightness = 0
        Part1.Material = Enum.Material.SmoothPlastic
        wait(Loop)

        Part1.Brightness = 1
        Part1.Material = Enum.Material.Neon
        wait(Loop)
    end
end
1 Like

This is not how variables work in LUA. You are overiding what the variabled data is every time you set the material. The light is good because you just set a property not the variable itself.

Try this:

    local Light = game.Workspace.Lamp1.Part1.PointLight
    local material = game.Workspace.Lamp1.Part1

    while true do
wait(0.4)
 Light.Brightness = 0
  material.Material = Enum.Material.SmoothPlastic
wait(0.5)
Light.Brightness = 1
  material.Material = Enum.Material.Neon
wait(0.3)
 Light.Brightness = 0
	material.Material = Enum.Material.SmoothPlastic
wait(0.1)
	Light.Brightness = 1
 material.Material = Enum.Material.Neon
end

I like your response but im trying to teach him 1 lesson at a time. You can’t use variables like that(the lesson). I do think your method is better but im not trying to confuse him.

Fair enough, it’s just that most members here would recommending changing the code since it’s a bit unoptimized (If you get what I mean)

Yeah I know, but I’d rather go with something I can understand more since I am new at scripting.