Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How may I fix this to make the material of the light itself not the pointlight change?

(This has been solved thanks to Danny/14zanderblitz. Despite zander's answer being incorrect, it still helped me realize the correct way to do it. So i will still give him the kudos of having the right answer, but I will edit the code I posted to show what the right way was)

I am trying to make a light switch box, and when you click the switch, it will flip up, and stay there for 2 seconds before flipping back down, this is due to the fact I do not know how to make it work whenever the light switch stays in the upright position, but that's besides the point. I want to make a red light come on to indicate the power is on, and to add to it, I want to make the material of the light shine, hense the reason I want it to be neon, sorry if this doesn't exactly make sense. Here is my code:

light = script.Parent.Parent.Parent.LightBulbRed -- This is the light bulb
switch = script.Parent.Parent -- This is the switch

function onClick ()
	if light.PointLight.Range == 0 then 
		light.PointLight.Range = 6
	else
		wait(2)
			light.PointLight.Range = 0 -- How bright you want it
	end
end
function material ()
	if light.Material == Enum.Material.SmoothPlastic then
		light.Material = Enum.Material.Neon
	else
		wait (2)
			light.Material = Enum.Material.SmoothPlastic
	end
end
script.Parent.MouseClick:Connect(onClick)
script.Parent.MouseClick:Connect(material)

Thank you Danny and Zander

2 comments

0

Material is an enum value

0

Thank you for accepting my answer, though I realized what I missed, I'll just change the answer to the correct way of doing things. Cheers!

1 answer

✓ Accepted answer

Like Danny said, material is a string or an enum.

light = script.Parent.Parent.Parent.LightBulbRed -- This is the light bulb
switch = script.Parent.Parent -- This is the switch

function onClick ()
    if light.PointLight.Range == 0 then 
        light.PointLight.Range = 6
    else
        wait(2)
            light.PointLight.Range = 0 -- How bright you want it
    end
end
function material ()
    if light.Material == Enum.Material.SmoothPlastic then --//This is correct. Materials can be a string, but won't always work. That's why I changed it to an enum
        light.Material = Enum.Material.Neon
    else
        wait (2)
            light.Material = Enum.Material.SmoothPlastic
    end
end
script.Parent.MouseClick:Connect(onClick)
script.Parent.MouseClick:Connect(material)

Please see if that works, and if it does, please accept my answer. Cheers, Zander.

2 comments

0

Sorry, it does not work, but thanks to you and Danny, you have helped me figure out a solution to my issue, what i had to do was instead of put "if light.Material == "SmoothPlastic" I had to put "if light.material == Enum.Material.SmoothPlastic

0

Lol k

This discussion is preserved as it was. New answers, comments, and votes are closed.