HTTP service taking too long/not working

I started using HTTP service in my game today to replicate a table across multiple places. However, sometimes the studio/game takes too long or doesn’t work and the script gets completely broken. Any ideas on how to solve this issue?

(The Pastebin has 552 lines of dictionaries and lists)

local httpService = game:GetService("HttpService")
local url = "https://pastebin.com/raw"
local leaguesTable
pcall(function()
	leaguesTable = httpService:JSONDecode(httpService:GetAsync(url))
end)
if not leaguesTable then
	warn("Data wasn't found!")
end

Have you tried waiting for the table to exist?

HTTP Requests can be kind of “on and off”. A good practice is to wrap them in a pcall. I’d recommend that if that’s a static table, just store it in a module script. If it is being constantly updated, I’d just store it in the game’s datastore, and retrieve it at place start. You can either save the table to the datastore using a script, or using a plugin like Datastore Editor.

I tried putting a wait() at the end of the 5th line but then the warn activates

I used to have ModuleScripts doing the work but my game divided into 5 places and it was painful to open each one daily just to change 1/2 items. About the game’s datastore I’m going to look more into it.

No i mean, I’m not sure if it exists, but something like a :WaitForChild() to wait for the table to exist

It could also be pastebin. I’ve never personally worked with it, but the API could just be slow. You could try trying to using an HTTP get on some other site. Also, this might be dumb of me to ask, but you have Allow HTTP Requests enabled in the game settings, right?

I tried looking in the devForum but found nothing. I guess it probably doesn’t exist

If you print the result of the pcall it might tell you why it’s failing

Yes, allow HTTP requests is turned on with sometimes the script working the way it should be. As for Pastebin being slow, do you have any other API recomendations?

I haven’t really used HTTPService before, so I don’t really have a “favorite” API. I would imagine that storing everything in a github repo like wally does would probably be pretty consistent. I also know that a lot of people use Trello for stuff. The most prominent example of that is probably in conjunction with Adonis Admin to handle and persist bans. Both of those sites have their own API documentation you could find easily.

sometimes the script working the way it should be

if the script works correctly–even if only sometimes–then it’s likely not the fault of an underlying issue with any of your code on HTTPService. It seems like it’s just either hang-ups on the API’s end, or on Roblox’s end. I would recommend wrapping the HTTP in a pcall to catch errors, and/or using a library like Promise (by evaera or Quenty; they’re both good in their own way) to handle your HTTP requests. (If it’s a problem with the API, then Promises won’t help, but if it’s like @Dede_4242 said, that you just need to wait longer, promises have a great API for handling values that don’t exist, but will).

Instead of HttpService:Get, you could use HttpService:Request to get more information about the response from pastebin.

1 Like

It worked! Thanks!
I don’t why httpService:GetAsync() just refuses to work most of th time, though.

local response = httpService:RequestAsync({
	Url = "https://pastebin.com/raw",
	Method = "GET"
})

-- Inspect the response table
local decodedResponse
if response.Success then
	print("HttpService request ON!")
else
	print("The request failed:", response.StatusCode, response.StatusMessage)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.