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

How do I enable/disable something during a certain period of time?

Asked by 3 years ago

I want to make a GUI visible in my game, my code is

while wait(0.1) do if game.Lighting:GetMinutesAfterMidnight() > 8 * 60 then script.Parent.Visible = true end if game.Lighting:GetMinutesAfterMidnight() > 10 * 60 then script.Parent.Visible = false end end

(Sorry for the bad spacing im new to the website and idk how to do the formats and spacings, any help will be appreciated. Thx a lot.)

0
the question is a bit ambiguous, do you mean period of time in the game or in real life time? btw to format code you can click the little blue circle and put the code between the lines enzotinman1 23 — 3y
0
Hi, thx for the comment. My code is basically if the time in game is larger than 8 o clock, the GUI will be visible and if the time is larger than 10, it wont be visible. It kinda works when i change the time manually but when it goes with the day night cycle script, it doesnt work. Do you know how to fix this? Thanks! ian091814 -5 — 3y
0
Hi, sorry for the late reply. I saw your answer and i tried, how does it work for you? I put in under the text label inside starter GUI, however it doesnt work, can you tell me which day night cycle are you using to make it worK? Thanks! ian091814 -5 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
while wait(0.1) do
    if game.Lighting:GetMinutesAfterMidnight() > 8 * 60 then
        script.Parent.Visible = true
    end
    if game.Lighting:GetMinutesAfterMidnight() > 10 * 60 then
        script.Parent.Visible = false
    end
end

btw heres the formatted script but idk why it doesnt work

Ad
Log in to vote
0
Answered by 3 years ago

not sure if you have solved this already but something like this could work

game:GetService("Lighting").Changed:Connect(function()
    local minutes = game:GetService("Lighting"):GetMinutesAfterMidnight()
    if minutes > 8 * 60 and minutes < 10 * 60 then
        script.Parent.Visible = true
    else
        script.Parent.Visible = false
    end
end)

this works for me but im not entirely sure why yours wouldn't work

0
Hi, sorry for the late reply. I saw your answer and i tried, how does it work for you? I put in under the text label inside starter GUI, however it doesnt work, can you tell me which day night cycle are you using to make it worK? Thanks! ian091814 -5 — 3y

Answer this question