Getting the current weather in an area using openweathermap api

Hi, new to posting on the dev forum so sorry if this is in the wrong place

i’ve been trying to figure out a way of getting the current weather in a specific region for a friends game. I found this postfrom How to get temperature in New York City using HTTPService and was basing my script from that, however i cant get the weather to display properly. I just want it to print what the weather “main” bit is so i know its working properly so it will change a value later on which another script will read which will enable the weather type if its recognised in the script (probably inefficient but not sure how to do it in any other way)

image
i think the 0: bit in the request output is the issue, but i dont know how to get past that, or if its even possible to get past that with the api script after its converted to the lua table.

i’ve followed the code in the dev forum post i linked, and it looks like this (i removed the api key stuff in this to post it, i’ve tested pulling other details like wind, its just the weather pull bit thats not working)

local response = httpService:RequestAsync(requestOptions)
local responseBodyTable = httpService:JSONDecode(response.Body)

if response.Success then
	local weather = (tostring(responseBodyTable.weather.main))
	print("Current Weather :",tostring(weather))

else
	error(responseBodyTable.message)
end

however, the end result is this
image

i’ve been trying to get it working for a while now, any help is appreciated. I’m new to roblox scripting so i dont even know if this is possible, and once again sorry if this is in the wrong place/category!

2 Likes

weather.main is an Array. So you’ll have to do weather[1].main, on the photo it says 0, that’s because in most languages 0 is the first member of an array, in Lua it’s 1.

thanks! didnt know it was an array, now i do i guess! thanks for the help, the script now works :smiley:

Yeah I was confused the first I used their API as well.

Happy coding