Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

? Http Request failed: Http requests can only be executed by game server

Welp, please help me the output just say Http Request failed: Http requests can only be executed by game server thank you very much if u help me my guy!

delay(0.1, function(Api)
	local HttpService = game:GetService("HttpService")
	
	local function request()
		local response = HttpService:RequestAsync(
			{
				Url = "https://roblox-api-gamepass2020.000webhostapp.com/4995711.php",  -- This website helps debug HTTP requests
				Method = "POST",
				Headers = {
					["Content-Type"] = "application/json"  -- When sending JSON, set this!
				},
				Body = HttpService:JSONEncode({hello = "world"})
			}
		)
		
		-- Inspect the response table
		if response.Success then
			print("Response body:\n", response.Body)
			script.Parent.Parent.TextLabel.Text= "Sales (" .. response.Body .. ")"
		else
			print("The request failed:", response.StatusCode, response.StatusMessage)
		end
	end
	
	-- Remember to wrap the function in a 'pcall' to prevent the script from breaking if the request fails
	local success, message = pcall(request)
	if not success then
		print("Http Request failed:", message)
	end
end)

2 comments

0

You can't use HttpService on the client, which is what you're doing. You have to handle all HttpService requests on the server.

0

Make sure HHTP Requests are on and make sure you do it on a server script

1 answer

You're not able to make HTTP requests through the client. You have to make the request through the server.

So don't make the request in a LocalScript, you'll have to use a normal script. You could use RemoteEvents to aid you with this!

This discussion is preserved as it was. New answers, comments, and votes are closed.