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

Can't change material through script?

This is in a regular script inside the part that is supposed to light up.

local a = script.Parent

while true do
	a.Material = "SmoothPlastic"
	wait(math.random(0,2))
	a.Material = "Neon"
end

It should be like a flickering light, but it only does line 4 and stops.

4 comments

0

wait should be in the end

0

tho this script does not make any sense

0

math.random(1, 2) and use enums (Enum.Material.MATERIAL_NAME)

0

how does this not make any sense? while true do (infinite loop) then change material, wait a random number, change material

2 answers

✓ Accepted answer

The part doesn't flicker because as soon as the part turns into a neon material it instantly changes back to plastic. In order to fix this you simply need to add a wait function after line 6.

like this:

local a = script.Parent

while true do
    a.Material = "SmoothPlastic"
    wait(math.random(0,2))
    a.Material = "Neon"
    wait(math.random(0,2)) -- This wait needs to be added.
end

3 comments

0

That's truer answer actually

0

Use "Enum" oof

0

Thanks it worked! I should've seen that though lol

You do several things wrong here, but I suffered from same problems back when I started, there's nothing to worry about.

Lua doesn't actually know what Smooth Plastic, or Neon is. Instead it knows what Enum.Material.Neon or Enum.Material.SmoothPlastic is, because this time it doesn't treat those as ordinary string, but as types which can be assigned to different things. You can find literally everything in Enum.
Enum is translating things that only we humans know, to lua.

Also Note to make sure that your script is server script and not Local Script

2 comments

0

roblox can cast strings into enum types for the right purpose, but enums are cooler

0

Yeah

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