I was attempting to make a light switch in studio which when clicked would turn on a light and change the part material of the light to neon. Everything was working out fine until I got to changing the material through an if-then statement. Through multiple tests on a different part I determined that for whatever reason, it doesn't seem possible to change the material of a part through an if-then statement. Can anybody help me with either creating new code or bugfixing? Thank you!
Light switch code:
local sPC = script.Parent.ClickDetector
local pointLight = script.Parent.Parent:FindFirstChild("Light"):FindFirstChild("PointLight")
local glow = script.Parent.Parent:FindFirstChild("Light").neon:GetDescendants()
local function hitDaLights(player)
if pointLight.Enabled == true then
pointLight.Enabled = false else
pointLight. Enabled = true
end
end
local function neon()
for index, descendant in pairs(glow) do
if glow.Material == "Neon" then
glow.Material = "SmoothPlastic" else
glow.Material = "Neon"
end
end
end
sPC.MouseClick:connect(hitDaLights)
sPC.MouseClick:connect(neon)

1 comment
Hmm, so I tried that in a separate part and it worked just fine, but in the code I'm using I'm trying to turn two parts Neon when clicked. Maybe I incorrectly used the GetDescendants() function? Also thank you for responding! :)