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

Can't change material through script?

Asked by
corbenv 17
4 years ago

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.

0
wait should be in the end Igoralexeymarengobr 365 — 4y
0
tho this script does not make any sense Igoralexeymarengobr 365 — 4y
0
math.random(1, 2) and use enums (Enum.Material.MATERIAL_NAME) Fifkee 2017 — 4y
0
how does this not make any sense? while true do (infinite loop) then change material, wait a random number, change material corbenv 17 — 4y

2 answers

Log in to vote
1
Answered by
ScuffedAI 435 Moderation Voter
4 years ago

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

0
That's truer answer actually GooierApollo664 183 — 4y
0
Use "Enum" oof FixRobloxz 61 — 4y
0
Thanks it worked! I should've seen that though lol corbenv 17 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

0
roblox can cast strings into enum types for the right purpose, but enums are cooler Fifkee 2017 — 4y
0
Yeah GooierApollo664 183 — 4y

Answer this question