Material/Color isn't changing in script

  1. What do you want to achieve? I have a light fixture in my game and I am attempting to make it flicker, as if the power in the facility is dying.

  2. What is the issue? The color and material of the light fixture isn’t changing.

  3. What solutions have you tried so far? None, as all of them I had already.

local light = script.Parent.PointLight
local lightMat = script.Parent.Material
local lightCol = script.Parent.BrickColor

local plastic = Enum.Material.Plastic
local neon = Enum.Material.Neon

local white = BrickColor.new("Institutional white")
local grey = BrickColor.new("Light stone grey")

lightMat = neon
lightCol = white
light.Enabled = true

while wait() do
	light.Enabled = false
	lightMat = plastic
	lightCol = grey
	wait(math.random(1,4))
	light.Enabled = true
	lightMat = neon
	lightCol = white
	wait(math.random(1,4))
end

This is my light fixture setup in the hierarchy:

Screenshot 2021-05-26 201501

And this is some footage of it not working:

As you can see, the PointLight itself goes on and off, but the material doesn’t change. Please help, I’m desperate lol

You can’t change a part’s property through a variable, you have to actually index the property every time to change it

What you’re doing:
lightMat = plastic

What you should be doing:
script.Parent.Material = plastic

2 Likes

The reason this script doesn’t work is because you are storing the part’s fixed material in a variable, like Send_Scripts mentioned you have to directly index it or else it will only redefine the variable not change the part.

Thank you so much! That worked! :smiley: