I tried to tell the script that when the brick was clicked, it would change from Plastic to Wood. It's properties show it's plastic. But when I test the script it doesn't work.
function changeMaterial() if script.Parent == "Plastic" then script.Parent = "Wood" end end script.Parent.ClickDetector.MouseClick:connect(changeMaterial)
Okay, well, there's a few things wrong with this code.
function changeMaterial() if script.Parent == "Plastic" then --This tells the script to look for an object called "Plastic". This is wrong. script.Parent = "Wood" --Likewise, this is trying to change the parent of this, making it a child of "Wood". This throws an error because you supplied a string on an object request. end end script.Parent.ClickDetector.MouseClick:connect(changeMaterial)
You need to use an Enum
.
function changeMaterial() if script.Parent.Material == Enum.Material.Plastic then script.Parent.Material = Enum.Material.Wood -- This changes the material, rather than the parent. end end script.Parent.ClickDetector.MouseClick:connect(changeMaterial)
You're welcome, tell me if you have any problems.