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

What does my TimeOfDay GUI work in studio mode but not in server mode?

So I have this day/night script and a GUI in my game that displays the TimeOfDay in a TextLabel. The day/night script works in both studio and server mode, but the GUI only works in studio mode - in server mode, the text remains as "08:00 am" despite the time passing.

Day/night script (server script placed in Workspace)


DAY_TIME_IN_MIN = 24 -- I set this to 24 so that each minute in game = 1 second real time

local dhour = 8 -- starts at 08:00
local dmin = 0
while true do
	wait(DAY_TIME_IN_MIN/24) 
	dmin = dmin + 1
	if dmin >= 60 then
		dmin = 0
		dhour = dhour + 1
		if dhour >= 24 then
			dhour = 0
		end
	end
	game.Lighting.TimeOfDay = dhour..":"..dmin
end

Script that updates the player's GUI according to TimeOfDay (server script placed in ServerScriptService)


game.ReplicatedStorage:WaitForChild("DayNight")

game.ReplicatedStorage.DayNight.OnServerEvent:connect(function(Player)
	print("started")
	while true do
		wait()
		if (tonumber(string.sub(game.Lighting.TimeOfDay,1,2))) == 12 then
			Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = 	
(tonumber(string.sub(game.Lighting.TimeOfDay, 1, 2))) .. 
string.sub(game.Lighting.TimeOfDay, 3, 5) .. " pm"
		elseif (tonumber(string.sub(game.Lighting.TimeOfDay,1,2))) == 00 then
			Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = 
(tonumber(string.sub(game.Lighting.TimeOfDay, 1, 2)) + 12) ..                                                 
 string.sub(game.Lighting.TimeOfDay, 3, 5) .. " am"
		elseif (tonumber(string.sub(game.Lighting.TimeOfDay,1,2))) > 12 then
			Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = 
(tonumber(string.sub(game.Lighting.TimeOfDay, 1, 2)) - 12) .. 
 string.sub(game.Lighting.TimeOfDay, 3, 5) .. " pm"
		elseif (tonumber(string.sub(game.Lighting.TimeOfDay,1,2))) < 12 then
			Player.PlayerGui.ScreenGui.Frame.TextLabel.Text = 
tonumber(string.sub(game.Lighting.TimeOfDay, 1, 2)) .. 
string.sub(game.Lighting.TimeOfDay, 3, 5) .." am"
		end
	end

end)

Script that fires a RemoteFunction called DayNight (this is a localscript placed in StarterGui)

game.ReplicatedStorage.DayNight:FireServer()

I tested the GUI script by adding

print("works")

in the GUI script when the event is fired, which the statement gets outputted in the server log -so I'm a bit confused why the TextLabel doesn't display TimeOfDay correctly...

1 answer

If you use FE then the server can't access the clients for security reasons. Consider using RemoteFunctions or RemoteEvents to request or set aspects of the client.

The problem is that you're using a RemoteEvent that modifys the client from the server. As I stated above that will not work. Instead try using the OnClientEvent function in a local script running on the client.

5 comments

0

I'm using RemoteEvent which is called DayNight, placed in ReplicatedStorage

0

Ok

0

Read my edits.

0

Don't worry it's fixed. Thanks anyway

0

Please close your question if it's fixed.

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