I’m trying to get the current weather in San Diego with OpenWeatherMap. All of this is working except for one part: the description. When I print the output, everything comes out perfectly except for the description:
Output
As you can see, it all comes out as nil, and I have no idea why. I’m following this JSON response from the OpenWeatherMap tutorial on how to make an API call, too.
JSON response
"coord": {
"lon": -122.08,
"lat": 37.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 282.55,
"feels_like": 281.86,
"temp_min": 280.37,
"temp_max": 284.26,
"pressure": 1023,
"humidity": 100
},
"visibility": 10000,
"wind": {
"speed": 1.5,
"deg": 350
},
"clouds": {
"all": 1
},
"dt": 1560350645,
"sys": {
"type": 1,
"id": 5122,
"message": 0.0139,
"country": "US",
"sunrise": 1560343627,
"sunset": 1560396563
},
"timezone": -25200,
"id": 420006353,
"name": "Mountain View",
"cod": 200
}
And here is my code:
local RE = game.ReplicatedStorage:WaitForChild('SendWeather')
local httpService = game:GetService("HttpService")
local requestOptions = {
Url = "http://api.openweathermap.org/data/2.5/weather?id=" ..
"5391811" .. -- id for city
"&apikey=" ..
'secretiveapikeyishallnotshow';
Method = "GET";
}
local response = httpService:RequestAsync(requestOptions)
local responseBodyTable = httpService:JSONDecode(response.Body)
local function kelvinsToFahrenheit(temp)
return temp * 9/5 - 459.67
end
if response.Success then -- if it succeeded (your API key is valid)
local temperature = kelvinsToFahrenheit(tonumber(responseBodyTable.main.temp)) -- convert to fahrenheit
local description = tostring(responseBodyTable.weather.description)
local humidity = tostring(responseBodyTable.main.humidity)
local clouds = tostring(responseBodyTable.clouds.all)
print("san diego weather:", tostring(temperature) .. "°F") -- output the temperature
print('san diego description: '..description)
print('san diego humidity: '..humidity..'%')
print(clouds)
RE:FireAllClients(tostring(temperature) .. "°F", description, humidity..'%')
else
error(responseBodyTable.message) -- throw an error based on the response they gave
end