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

Is there any possible way to have a GUI tween onto the screen once night falls?

Asked by 6 years ago

What I'd like to do is have a GUI tween onto the screen when a certain time of night hits, but I have no earthly idea how to do that. All that I need is something that just activates it when a "Sky" object hits, like, midnight.

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Nothings impossible. To do this let's use the event LightingChanged of lighting + GetMinutesAfterMidnight() function to check

game.Lighting.LightingChanged:connect(function(skyboxchanged)

end)

Next let's check that it wasn't skybox that changed

game.Lighting.LightingChanged:connect(function(skyboxchanged)
    if skyboxchanged==false then

    end
end)

Also let's create a tween function + a check function with a bounce This will make it so that the tween function will only run once when it enters night

function tween()
    --stuff
end

local init = false
local last = init
function check()
    if init==true and last~=init then
        tween()
    end
    last=init
end

Now to check what time it is

game.Lighting.LightingChanged:connect(function(skyboxchanged)
    if skyboxchanged==false then
        if (game.Lighting:GetMinutesAfterMidnight()>1200 and game.Lighting:GetMinutesAfterMidnight()<1439) or (game.Lighting:GetMinutesAfterMidnight()<300 and game.Lighting:GetMinutesAfterMidnight()>0) then
            init=true
            check()
        else
            init=false
            check()
        end
    end
end)

This will check if the time in when its dark and if so it'll change init to true and fire the check function who will then check if its only once which it enters night and then fire tween

Let's put it together,

function tween()
    --stuff
end

local init = false
local last = init
function check()
    if init==true and last~=init then
        tween()
    end
    last=init
end

game.Lighting.LightingChanged:connect(function(skyboxchanged)
    if skyboxchanged==false then
        if (game.Lighting:GetMinutesAfterMidnight()>1200 and game.Lighting:GetMinutesAfterMidnight()<1439) or (game.Lighting:GetMinutesAfterMidnight()<300 and game.Lighting:GetMinutesAfterMidnight()>0) then
            init=true
            check()
        else
            init=false
            check()
        end
    end
end)

And here's it together with a tween function in the tween function (lol)

local gui = script.Parent
function tween()
    gui:Tween(stuff)
end

local init = false
local last = init
function check()
    if init==true and last~=init then
        tween()
    end
    last=init
end

game.Lighting.LightingChanged:connect(function(skyboxchanged)
    if skyboxchanged==false then
        if (game.Lighting:GetMinutesAfterMidnight()>1200 and game.Lighting:GetMinutesAfterMidnight()<1439) or (game.Lighting:GetMinutesAfterMidnight()<300 and game.Lighting:GetMinutesAfterMidnight()>0) then
            init=true
            check()
        else
            init=false
            check()
        end
    end
end)
0
Now would this go inside the gui itself or would it go into workspace? Auto2359 27 — 6y
0
@Auto2359 A localscript, then point the variable 'gui' towards your gui and add you args to the tween function DanzLua 2879 — 6y
Ad

Answer this question