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

How to change material script?

Asked by
Anto3oo 13
5 years ago

Im trying a kind of lamp to bright when its nightime (my game has it) but this doesnt work , help!

if game.Lighting.ClockTime = 18 then
    script.Parent.Material = [Neon]
end

2 answers

Log in to vote
1
Answered by 5 years ago

Hello!

First of all, you should be constantly checking if it is nighttime, about every second or minute, depending on how fast your day turns out to be.

You can use a while loop for this. Next, you will want to check if the value is 18 or later, you can use >= 18 for this, as it will check if it is 18 or higher. Next, you want to change it to the Neon material, then you will have to use Enum.Material.Neon.

Now, let's turn this logic into code.


local Lighting = game:GetService("Lighting"); -- Our while loop while true do -- Checking if the time is 18 or more. if Lighting.ClockTime >= 18 then -- Let's change the lamp's material to Neon! script.Parent.Material = Enum.Material.Neon; else -- Change it to SmoothPlastic if it isn't late :D script.Parent.Material = Enum.Material.SmoothPlastic; end wait(1) -- Waits a second before continuing end
0
ohhhhhhhhhh got it , Thanks! Anto3oo 13 — 5y
0
Might want to use Lighting.Changed instead of a while loop if you're on a slower cycle. RubenKan 3615 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I think the problem is that you need to put the material in quotes, like this:

if game.Lighting.ClockTime = 18 then
    script.Parent.Material = "Neon"
end

The issue you had with your script is that you are not supposed to put a material in brackets like that unless you need to use a parameter in a function or a variable when you are trying to reference something like if I were to do this

local Key = "J"
local Thing = Enum.KeyCode[Key]

I hope this helps. If it does not, it is probably because you are not showing us enough of your code. Accept if this helps. Thank you.

0
Thanks! i got it to work! Anto3oo 13 — 5y

Answer this question