Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

This Streetlight script doesn't work after the first end statement?

Asked by 7 days ago

It appears to work up until the first 'end'.

local LightPart = script.Parent
local SurfaceLight = LightPart.SurfaceLight

while true do 
    wait(0.1)
    if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
        LightPart.Material = Enum.Material.Glass
        SurfaceLight.Enabled = false
    end
    if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
        LightPart.Material = Enum.Material.Neon
        SurfaceLight.Enabled = true
    end
end
0
What do you mean by 'first end'? Dovydas1118 1072 — 7d
0
We need your day/night script. TTChaos 731 — 7d

1 answer

Log in to vote
0
Answered by
TTChaos 731 Moderation Voter
7 days ago
Edited 7 days ago

You need to use the modulus operation to see which hour it is.

I'm working on an explanation right now, don't worry

local LightPart = script.Parent 
local SurfaceLight = LightPart.SurfaceLight
local Lighting = game:GetService("Lighting") -- Get lighting
local Hour -- Define hour

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    Hour = Lighting.ClockTime % 24 -- Get hour
    if Hour < 18 and Hour > 6 then -- If hour is between 6 AM and 6 PM then
        LightPart.Material = Enum.Material.Glass -- Change to glass
        SurfaceLight.Enabled = false -- Disable light
    else -- Otherwise
        LightPart.Material = Enum.Material.Neon -- Change to neon
        SurfaceLight.Enabled = true -- Enable light
    end
end)
Ad

Answer this question