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

Why do my lights turn off, but not back on?

Asked by 8 years ago
Edited 8 years ago

Pretty self explanatory... They'll turn off at 06:00:00, but when it comes to 18:00:00, they don't turn on.. :/

Update (Added prints)

minutesAfterMidnight = 0

function checkDecendants(parent, enabled)
    print(enabled)
    for i, v in pairs(parent:GetChildren()) do
        if #v:GetChildren() > 0 then
            checkDecendants(v)
        end

        if v.Name == "SpotLight" then
            v.Enabled = enabled
            if enabled then
                v.Parent.Material = Enum.Material.Neon
            else
                v.Parent.Material = Enum.Material.SmoothPlastic
            end
        end
    end
end


while true do
    minutesAfterMidnight = minutesAfterMidnight + 2
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(0.1)

    print(game.Lighting:GetMinutesAfterMidnight(), minutesAfterMidnight)

    if game.Lighting:GetMinutesAfterMidnight() == 360 then      -- checks for 6AM
        print("Off")
        checkDecendants(game.Workspace, false)
    elseif game.Lighting:GetMinutesAfterMidnight() == 1080 then     -- checks for 6PM
        print("On")
        checkDecendants(game.Workspace, true)
    end
end

output:

4 4  -358 358
360 360
Off
false
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
362 362
364 364 - 1078 1078
1080 1080
On
true
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
nil
1082 1082
1084 1084
0
why not just if minutesAfterMidnight instead of the whole thing from lighting arrowman888 69 — 8y
0
Because minutesAfterMidnight doesn't reset to 0. TestingPlace1337 51 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Fix.. I realized that calling checkDecendents(v) didnt take the enabled parameter, so it passed nil as the argument.

minutesAfterMidnight = 0

function checkDecendants(parent, enabled)
    for i, v in pairs(parent:GetChildren()) do
        if #v:GetChildren() > 0 then
            checkDecendants(v, enabled)
        end

        if v.Name == "SpotLight" then
            v.Enabled = enabled
            if enabled then
                v.Parent.Material = Enum.Material.Neon
            else
                v.Parent.Material = Enum.Material.SmoothPlastic
            end
        end
    end
end


while true do
    minutesAfterMidnight = minutesAfterMidnight + 2
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(0.1)

    print(game.Lighting:GetMinutesAfterMidnight(), minutesAfterMidnight)

    if game.Lighting:GetMinutesAfterMidnight() == 360 then      -- checks for 6AM
        checkDecendants(game.Workspace, false)
    elseif game.Lighting:GetMinutesAfterMidnight() == 1080 then     -- checks for 6PM
        checkDecendants(game.Workspace, true)
    end
end
Ad

Answer this question