I have a GUI set to "pop up" at a certain time, using the time from a simple time-changing script in the workspace. Presented below are my scripts, the GUI works in Studio solo mode but not when published.

Time-changing script located in Workspace:

_G.Hello = 'I am global variable'

_G.MinutesAfterMidnight = 445 -- starting time, change to 419 for 7am

while true do 
	_G.MinutesAfterMidnight = _G.MinutesAfterMidnight + 1 -- don't change, 1 minute changes
	game.Lighting:SetMinutesAfterMidnight(_G.MinutesAfterMidnight)
	wait(1) -- how long it takes for time to pass, example change to 5 for 5 minutes, 3 to 3 minutes per hour
	
end

My LocalScript in the StarterGui that tells the GUI to fire:

player = game.Players.LocalPlayer


while true do
	MinutesAfterMidnight = _G.MinutesAfterMidnight
	print(MinutesAfterMidnight) 
	wait(1)	
	if MinutesAfterMidnight == 465 then
		game.ReplicatedStorage.Fire:FireServer("Breakfast is served in the cafe!", 7)
	end
end

If needed, the GUI script is here:

local bg = script.Parent.BG
local text = bg.Text

game.ReplicatedStorage.Fire.OnServerEvent:connect(function(player, message, seconds)
	text.Text = message
	local size = bg.Size.Y.Scale
	bg:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", 2, true) --Gui coming out
	wait(seconds)
	bg:TweenPosition(UDim2.new(0, 0, -size, 0), "Out", "Quad", 2, true) --Gui going in
	text.Text = ""
end)

The GUI WAS popping up and working when the time-changer and the GUI fire command were in the same scripts, in a local script in startergui. however, I had to split them up and add a global variable due to a time bug spazzing between 2 different times depending on when the other player joined (resetting the time). I am pretty sure the bug lies within the local script presented. Thanks for your help!

1 comment

1

"Keep in mind that the server has a different _G than clients do, so you can't define a global function in a server script and then use it from a LocalScript." Also, you may have a problem with the LocalScript firing the RemoteEvent before the GUI script has a chance to load.