I need help with my code to connect to when it gets dark it turn neon and when it turns light goes back to plastic why my code not working

While true do
Script.parent.Material = (Neon)
Wait (40)
Script.parent.Material = (Plastic)
Wait (78)
End

1 Like

You are indexing a color as (Neon) and (Plastic). Your capitalization is also incorrect. Do this:

while true do
    script.Parent.Material = 'Neon'
    wait(40)
    script.Parent.Material = 'Plastic'
    wait(78)
end

In the future, please format your code using ```lua. It would also be nice if you could shorten your title and explain it more in the topic itself!

It works I am on mobile and trying to remember my code so how would I connect it to daylight cycles

1 Like

You can use game.Lighting:GetMinutesAfterMidnight() inside of an if statement for switching the materials. Here is an example:

local lighting = game:GetService("Lighting")

while true do
      local minutesAfterMidnight = lighting:GetMinutesAfterMidnight()
      -- if time is between 6pm and 6am then the material is neon, otherwise it is plastic
      if minutesAfterMidnight <= 6*60 or minutesAfterMidnight >= 18*60 then
            script.Parent.Material = 'Neon'
      else
            script.Parent.Material = 'Plastic'
      end
      wait(1)
end