HTTP 500 error for a weather script

Hello, im making a weather script, which detects your weather in real life. so bassicly im trying to do a
http request on studio it works, but in a game it does not and it shows this error

-- scipt for server
local HttpService = game:GetService("HttpService")
game.ReplicatedStorage.Data.OnServerInvoke = function(plr, url)
	local response = HttpService:GetAsync(url)
	local data = HttpService:JSONDecode(response)
	return data
-- script for client
local function getWeather()
	local url = ""..Location.."/today?unitGroup="..DataUnits.."&include=days&key="..ApiKey.."&contentType=json"
	local data = game.ReplicatedStorage.Data:InvokeServer(url)
	return data

I’m not very good at that http thing so i get confused easily

1 Like

hi, there’s a specific problem in your script that stands out and could be the culprit

in your client script, the way you’re constructing the url string seems incorrect due to concatenation

the quotation marks and concatenation operators (.. ) are inside the string, which means they are being treated as literal characters instead of operators to concatenate the variables Location , DataUnits , and ApiKey to your URL string, so this would result in an invalid URL being passed to the server script, causing the HTTP 500 error when the server tries to make the request with this invalid URL

to fix the URL construction, make the following changes like this:

local Location = "your_location" 
local DataUnits = "metric" 
local ApiKey = "your_api_key"
local url = "" .. Location .. "/today?unitGroup=" .. DataUnits .. "&include=days&key=" .. ApiKey .. "&contentType=json"


didnt work, it looks like the same url that you wrote or is it just me?

There is nothing wrong with how he’s constructing the url, the concatenation operators aren’t inside the strings. Where are you seeing that exactly?

EDIT: I also suggest constructing it on the server side, mostly due to your api key.

It’s the same thing, could you show your Location, and DataUnits variables?