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

Problem with Basic Material and Color Changing Script?

Asked by
laripo 17
4 years ago

So I have this script which is supposed to reproduce a sort of flashing neon, the script functions because in the output in prints 'Script Works' after every loop. However, my problem is that the color and the material of the brick don't change at all, they stay the exact same.

local material = script.Parent.Material
local color = script.Parent.BrickColor

function change_mat()
    material = Enum.Material.Neon
    wait(1)
    material = Enum.Material.Plastic
    wait(5)
    material = Enum.Material.Neon
    wait(.5)
    material = Enum.Material.Plastic
end

color = 'Red'

while true do
    change_mat()
    wait(1)
    print('Script Works')
end
0
I think the probably is assigning the parts property to a variable. Maybe, just define the part instead. awsomemike4 3 — 4y

2 answers

Log in to vote
0
Answered by
Yuuwa0519 197
4 years ago
Edited 4 years ago

First, for the part to change your color of brick.

When you want to change the colors of brick using BrickColor, you always have to use the BrickColor.new() to do it. Also, the brick color "Red" does not exist in Roblox apparently, so try to look for the right name by going to your part > BrickColor, then hover over the color you want to use for the right name. example :

local color = script.Parent.BrickColor
color = BrickColor.new("Lime green")

Now onto material of brick. As far as I know, you have to define the material like :

local part = script.Parent
part.Material = Enum.Material.Neon

instead of making a variable

material = part.Material

which won`t work.

Ad
Log in to vote
0
Answered by 4 years ago

First assign the part you will be changing to a variable, rather than the part's properties

Like so,

local Part = script.Parent

Since you said you wanted the part to flash, I would suggest taking out the long wait and replacing it with just one

(Btw, since this function is in a while loop, it will continuously loop, so you don't have to constantly change the parts material from neon to plastic, just once will do. :D

function change_mat()
     Part.Material = Enum.Material.Neon
    wait(0.5)
    Part.Material= Enum.Material.Plastic
  end

if you want to change the color of the brick to Red, you should set color equal to

Brickcolor.new("Really Red") -- (That's the name in roblox for Red, but you have various different shades, just look up Roblox Colors Names)

lastly connect it all in a while loop:

 while true do
        change_mat()
        wait(1)
        print('Script Works')
end

Hopefully this helps!

0
The reason for the multiple wait() is to have a different timing so that it doesn't constantly change at the same pace. But anyways thanks for your answer, it works! laripo 17 — 4y
0
you could even use the function "math.random" for different timing, like : wait(math.random(the lowest numer you want, highest number you want)) Yuuwa0519 197 — 4y

Answer this question