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

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

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

2 comments

0

What do you mean by 'first end'?

0

We need your day/night script.

1 answer

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)

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