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

Time of Day = Whether or not a light is on/off?

Asked by 8 years ago

So. What I am trying to do is if the time is in-between "17:00:00" and "04:00:00" (game time) then the lights are turned on, but what I am also trying to do is change the material of the light itself.

while wait() do
    if game.Lighting.TimeOfDay >= "17:00:00" and game.Lighting.TimeOfDay <= "06:00:00" then
        script.Parent.PointLight.Enabled = true
        script.Parent.Material = Enum.Material.Neon
    else
        script.Parent.PointLight.Enabled = false
        script.Parent.Material = Enum.Material.Plastic
    end
end
0
Sorry, I tried to code on my phone. It didn't work very well as I couldn't test it. I got it the wrong way round and missed a ) on the end of the .Changed function. Hope this works for you! General_Scripter 425 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

Using the built in function of Lighting, GetMinutesAfterMidnight(), you an find the minutes after midnight (as the function's name suggests...). You can then check it's between 360 (06:00:00 - found by using the example on the wiki page) and 1020 (17:00:00 - found by using the example on the wiki page). You may also want to use game.Lighting.Changed instead of a forever loop as it's more efficient. Your final code would be this:

function changeLight()
    local tam = game.Lighting:GetMinutesAfterMidnight()
    if tam <= 1020 and tam >= 360 then -- If it's between 06:00:00 and 17:00:00
        script.Parent.PointLight.Enabled = false
        script.Parent.Material = Enum.Material.Plastic
    else
        script.Parent.PointLight.Enabled = true
        script.Parent.Material = Enum.Material.Neon
    end
end

game.Lighting.Changed:connect(function()
    changeLight()
end)

changeLight() -- Run to get initial status
0
Nope. :/ TheHospitalDev 1134 — 8y
0
Sorry, I tried to code on my phone. It didn't work very well as I couldn't test it. I got it the wrong way round and missed a ) on the end of the .Changed function. Hope this works for you! General_Scripter 425 — 8y
Ad

Answer this question