Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Make a GUI pop up at a certain time using the time from lighting?

Hello! I am trying to learn how to make a GUI pop up at a certain time using the time from lighting. I have a time-changing script and I would like a GUI to show up, for an example, when it hits 6:00:00 and disappears at 7:00:00.

This is my very first script I am trying to make, so it probably has a lot of errors, I apologize. Things like I don't know if ServerStorage is the correct place to store something like this, where I would put this script (I put it as an extension of the textbox), if I have the labeling correct, and if "Enabled" is the right term because I see the checkbox is actually called "Visible".

TextBox = game.ServerStorage.ScreenGui.TextBox
minutesAfterMidnight = 0
 
while true do
	minutesAfterMidnight = minutesAfterMidnight + 10
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(0.1)
 
	if game.Lighting:GetMinutesAfterMidnight() == 7 * 60 then		
		TextBox.Enabled = false
	end
	if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then		
		TextBox.Enabled = true
	end
end

Thanks :)

2 comments

0

For normal Server Scripts, you should use ServerStorage. For LocalScripts, you should use ReplicatedStorage.

0

Thanks!

1 answer

✓ Accepted answer

You should try using >= and <= rather than ==. Also since the gui is in server storage, it can't update for players. You should update time on the server, and update the gui on a local script.

This is due to floating point interpolation errors, so it would be better to do

if game.Lighting:GetMinutesAfterMidnight() < (7 * 60) and game.Lighting:GetMinutesAfterMidnight() > (6 * 60) then
TextBox.Enabled = true
else
TextBox.Enabled = false
end

(in a local script of course)

This discussion is preserved as it was. New answers, comments, and votes are closed.