Help with real time weather syncing system

Hello everyone, thank you for taking a look at my post, all help us definitely appreciated! Note: We solved the problem only partially, so to prevent spam, this post has been split into to problems instead of creating a new post.

Old Problem

Hello everyone, I am currently working on a one player game that syncs every aspect of the clients real world to the game. I currently have everything needed including time and lighting, except weather. I would really love some help on achieving a real time weather syncing system! Any help is appreciated! Good luck and thank you in advance! :wink:

New Problem

Edit: I think I found a possible solution, or at least one that gets the approximate weather. I know that (using the code from this YouTube video : Roblox Tutorial - How to make a live syncing weather system in Roblox - YouTube) you can set whether through time zones. I do know that you can also get the players local os.time. Meaning, that you can use normal calculations to get the players time zone, for example pacific time is eastern time - three hours. And now a new problem arises, how would I come about coding this?

5 Likes

you can get weather from httpservice but i dont think you can get the specfic irl location of a player? just the country theyre in using localizationservice
you could add a setting asking them for the location but no idea if thats allowed by guidelines

Well, I know you can get their local time pretty easily. So maybe you could get their time zone, which narrows their possible weather down, by simply taking a base time and seeing how it relates to their time. For example est to California is est time -3 hours.

For getting the time of the world what you could to to get the time

(Got the code from this post, although slightly modified)

local TIME_ZONE = -6 -- CST = UTC -6 so its "-6"
 
local date = os.date("!*t")
local hour = (date.hour + TIME_ZONE) % 24
local ampm = hour < 12 and "AM" or "PM"
local timestamp = string.format("%02i:%02i %s", ((hour - 1) % 12) + 2, date.min, ampm)

print(timestamp)

To get the timezone you would have to prompt your player sadly I do not believe there is any other way.

As for weather I believe this is impossible but the only guess I would have to do this would be HTTP Service to contact some server and then you would have some code on that server that would return the weather by the players local weather service? I’m not very experienced with HTTP service so I wouldn’t know how that would go, But yeah I can’t really provide anything more than a19_9 since its just a ROBLOX engine limitation really

1 Like

Oh and yeah you would have to prompt the player for their location which people will take as a red flag and just leave id bet, and I feel like that would be against TOS but im not sure

Ah, ok. I found this YouTube video. Sadley, it still doesn’t provide accurate weather because it depends on a fixed time zone. (Roblox Tutorial - How to make a live syncing weather system in Roblox - YouTube)

Ya, that wouldn’t be good. But I heard you can get their os.time without prompt which could lead to this being a solution:

Well, best of luck to you, your game idea is pretty cool!
And yes you can get their os time without prompting,

Oh hey I actually did some digging and this post is probably want you need for the time sync

1 Like

Quick question, do you know how I would create a base time that is always running in the background? My new plan is to detect the players time zone by basic calculations such as pacific time = eastern time - 3 hours. The only way to do this is to always have the time est in the background to make these conversions. I’m not sure how I would do this, but if you have any ideas any help would be appreciated.

roblox timezone in default is UTC so you can just subtract or add to it to get your preferred time?

Edit this as you please, so I made this which actually ends up actually solving your issue anyways and it sets the time automatically to the irl time of the player.

Of course still credit to this post for some the code used from them.

function getTime()
	local function pretty_date(date)
		local dateString = "{year}-{month}-{day} {hour}:{min}"
		local result = string.gsub(dateString, "{(%w+)}", date)
		return result
	end
	local now = os.time()
	local fullTime = pretty_date(os.date("*t", now))
	local returnTime = string.sub(fullTime, string.find(fullTime, " ") + 1, 9999)

	return returnTime

end

while wait(1) do
	print(getTime())
	game.Lighting.TimeOfDay = getTime()
end

Edit: Renamed function to fit more appropriately to what it does.

1 Like

How would I store this constant UTC time into a variable?

1 Like

Thread author here, just wanted to clarify this can be simplified using 24 hour mod instead of 12

local TIME_ZONE = 1

local date = os.date("!*t")
local hour = (date.hour + TIME_ZONE) % 24
local timestamp = string.format("%02i:%02i", hour, date.min)

print(timestamp)