Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to change a item material with a script?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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) 


Ad

Answer this question