How can I make it so that it shows your local time to others

Greetings,

I am making a game about showing your local time by using a GUI that is above your head like in this screenshot.
image_2023-06-11_162542771

But when I test it out in public servers, the time shows as 13:25 instead of 16:25 (in my time), I tried it out with a friend who lives in a different time zone and he has the same time as me. How can I fix this? (I might have explained it in a weird way but I hope you get the idea)

local function getCurrentTime()
	local currentTime = os.time()
	return os.date("%H:%M", currentTime)
end

local function updateTimeTextLabel(textLabel)
	textLabel.Text = getCurrentTime()
end

local function updateOtherPlayerTimeTextLabel(textLabel, player)
	local playerTime = player:GetAttribute("LocalTime")
	textLabel.Text = playerTime
end

local timeLabel = script.Parent

updateTimeTextLabel(timeLabel)

while true do
	wait(1)
	updateTimeTextLabel(timeLabel)
end

game.Players.PlayerAdded:Connect(function(player)
	local playerTimeLabel = script.Parent

	player.AttributeChanged:Connect(function(attribute)
		if attribute == "LocalTime" then
			updateOtherPlayerTimeTextLabel(playerTimeLabel, player)
		end
	end)

	updateOtherPlayerTimeTextLabel(playerTimeLabel, player)
end)

Also here is a screenshot on what I am talking about

You need to get the time using a local script and send it to the server, otherwise it will show the time zone of wherever the Roblox server is.

1 Like

Alright thanks, I will try to do that and see the results.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.