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

Why won't this turn on/off script turn ON?

Asked by 7 years ago
-- Turning On and off script

        Light = script.Parent.PointLight
while wait() do
if game.Lighting.TimeOfDay == "19:00:00" then
    Light.Enabled = true
    script.Parent.Material = "Neon"
else if game.Lighting.TimeOfDay == "06:00:00" then
    Light.Enabled = false
    script.Parent.Material = "DiamondPlate"

    end 
end
end

Is it just server lag or does the first if statement not work?

So I have this loop running in about 17 lamps in my game. All functioning in a regular script. Most simple job ever. Turn on at This and That time.

It turns off at 6:00:00, but it won't turn on at 19:00:00 UNIX time. Would a function work better in this situation?

Help?

1 answer

Log in to vote
0
Answered by
Etheroit 178
7 years ago
Edited 7 years ago

Try using that script

lightPart = game.Workspace.LightPart
minutesAfterMidnight = 0

while true do
    minutesAfterMidnight = minutesAfterMidnight + 10 -- Day/Night Cycle
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(1)

    if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then       -- checks for 6AM
        lightPart.Material = Enum.Material.Plastic
        lightPart.PointLight.Enabled = false
    end
    if game.Lighting:GetMinutesAfterMidnight() == 19 * 60 then      -- checks for 7PM
        lightPart.Material = Enum.Material.Neon
        lightPart.PointLight.Enabled = true
    end
end
0
I was right about the script moving too fast, but this script is a bit cleaner in my opinion. Thanks! :) RadioactiveP0P 44 — 7y
0
No problem ;) Etheroit 178 — 7y
Ad

Answer this question