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

How to change a item material with a script?

I am trying to change a item material from neon to plastic. Any idea on how to do that? I am working with this:

local light1 = workspace.light.Light1
local light = workspace.light.Light
local light2 = workspace.light.Light2
local light3 = workspace.light.Light3
local switch = workspace.switch
function onClick()
	wait(0.1)
	light.SurfaceLight.Brightness = 0
	light1.SurfaceLight.Brightness = 0
	light2.SurfaceLight.Brightness = 0
	light3.SurfaceLight.Brightness = 0
	light.Material = Plastic
	light1.Material = Plastic
	light2.Material = Plastic
	light3.Material = Plastic
end
switch.ClickDetector.MouseClick:connect(onClick) 

The light.material part does not work as in roblox it does not know what "plastic" is. How would I define this or is there a better way?

1 answer

✓ Accepted answer

Your almost there with your code. But you forgot a major part, string. When Changing certain values you must use string. This is the proper way

local light1 = workspace.light.Light1
local light = workspace.light.Light
local light2 = workspace.light.Light2
local light3 = workspace.light.Light3
local switch = workspace.switch
function onClick()
    wait(0.1)
    light.SurfaceLight.Brightness = 0
    light1.SurfaceLight.Brightness = 0
    light2.SurfaceLight.Brightness = 0
    light3.SurfaceLight.Brightness = 0
    light.Material =  "Plastic"
    light1.Material =  "Plastic"
    light2.Material =  "Plastic"
    light3.Material = "Plastic"
end
switch.ClickDetector.MouseClick:connect(onClick) 


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