I have a GUI set to "pop up" at a certain time, using the time from the lighting, and using a simple time-changing script located in the workspace. I use a local script that's in the PlayerGui that tells the GUI when to fire. (I have the Fire in the ReplicatedStorage) Presented below are my scripts, the GUI works in Studio solo mode but not when published.

Is there a better method than using a global variable to get the time? At first, I had the local script that tells the GUI to fire and the time-changing script in the same script in StarterGui, but that had caused a time glitch where the time would be constantly going back and forth between the player's times that are in the game. So, I know for sure that the time-changing script needs to stay in the workspace.. I am just having a difficult time letting the GUI script know what time it is (hence trying to use the global variable).

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)

Thanks for your help!

1 comment

0

Client and server have different copies of _G. Your changes to it on the server won't change it on the client; it works in studio because in studio your computer is both server and client.