HttpService returning nil on a table containing values

Hello! I was creating a plugin and now i need to get informations from a table located on guthub so i can notify the users when an update is available if they don’t check in the plugin manager. This is my code:

local httpService = game:GetService("HttpService")

local result = httpService:RequestAsync(
	{
		Url = "https://github.com/iKingNinja/Dialogs-editor-info/blob/main/DialogsEditorInfo.lua",
	}
)

print(result["Updates"])

Basically the script says that the table is nil and if i add [1] after [“Updates”] it says that there isn’t anything in the table. Below you can see the github repository, made with Visual Studio Code.

result["Updates"][1] should be false but it gives me this error: ServerScriptService.Script:9: attempt to index nil with number and prints nil without [1].

If i use :GetAsync() it gives me the error: HTTP 404 (Not Found)

I’m inexperienced in using http service since this is my first time…

The link in the function RequestAsync() is the link to the page that you can see in the picture above. Do you have any solution to the problem? Thanks!

  1. Going to that URL is a 404 error for me. So maybe it’s not publicly accessible anyways.

  2. RequestAsync returns a table with a bunch of info. To access the body you should do result.Body (See Response Dictionary Fields

  3. You might wanna check the result.Success or StatusCode/StatusMessage before that.

  4. Just print out the result.Body first (or try Debugging | Roblox Creator Documentation to step through line by line and examine variables).

  5. The Body will be a string, not a table. It will be HTML because you’re just pulling a random website page. I suggest you either use the raw text link at raw.githubusercontent.com (you go there from pressing the “view raw” button on the file view page) first, or you can use the official GitHub API.

  6. I would question why you’re doing this in the first place. It seems like a strange problem to want to solve.

2 Likes

Actually that repository was private, was that the problem?

Is this the field you are talking about? If yes do i set method to true? And what should i set for Headers?

Can i fix it using JSONDecode?

Because i just made a plugin that i want to release and i need it so when i change the value from false to true when a user launchs the plugin it will say that there’s an update available.

Firstly, the URL doesnt seem to contain anything, i cannot see the file, make sure it is public.

Secondly, the link you should use to access the file is “https:// raw.githubusercontent. com/iKingNinja/Dialogs-editor-info/blob/main/DialogsEditorInfo.lua”

Thirdly, you need to use result.Body, as “result” is a table of values with other things such as success and errorcode

Finally, the returned result will be a string, not something you can read off the table. What I would do is use comma separated values if you plan on having many variables on the github, and then use string.split to create a table manually

1 Like

yes, making it public will fix that. make sure you also use raw.githubusercontent.com

no, you have screenshotted the request table, that is fine as it is. Your “result” variable is a returned table, so you need to do result.Body to get the correct data. (after checking result.Success to prevent errors)

This is a good option. instead of having lua code in the file, make it a text file instead, containing JSON encoded data

1 Like

I would just stop using RequestAsync and use HttpService | Roblox Creator Documentation. It’s simpler to use:


local response

-- Use pcall in case something goes wrong
local success, err = pcall(function ()
    response = HttpService:GetAsync("https://raw.githubusercontent............")
end)

-- Did our request fail
if success then
    print("got response", response)
else
    warn("got error", err)
end

Edit: removed JSON parsing. Add it back if your file is indeed JSON.

2 Likes

Now it prints it as string:

image

I need it as a classic roblox table.

yes, as I said what I would do is JSON encode the raw file (make it a text file not a lua file). Then JSON decode the string which you recieve

1 Like

I edited the code so it prints the error if it errors.

Now your problem is that your text is lua code!

That’s a bad idea.

@joshuwonka is right. Don’t get lua code in the first place for this. Make a JSON file, put it on your GitHub, get that file, and then parse it with JsonDecode once you have the string.

2 Likes

Ok, but do you mean a normal text file as JSON file?

Like this:

I mean it doesn’t matter what the file extension is, if you put json inside of a file called .lua and just treat it as json, that’s fine. Just confusing.

The JSON equivalent of that table would be

{
  "Updates": true
}

So that’s the entire text you would put in your file.

2 Likes

Can I actually recommend something slightly different?

Ignore json and this updates Boolean entirely.

Keep a file at the top of your plugin’s repo called VERSION or something. It’s text would literally just be “1.0.0”.

Keep it in sync with a lua variable inside your plugin.

Your plug-in would then just GET that VERSION file, read the text directly (keep it as a string, no parsing needed), and compare it against the version of the code it’s running.

If it’s different, you need an update.

2 Likes

This is the best idea. Otherwise some users may not use the plugin just after the update and never see the notification. Do this, or if you plan on having more values in the file you could always save the version number as a string in the JSON instead of a boolean.

1 Like

Ok it seems a lot easier, but just to know if i have this script:

local httpService = game:GetService("HttpService")

local result = nil

pcall(function()

result = httpService:GetAsync("TheLinkThatTheForumBlocks")

end)

if result then

print(httpService:JSONDecode(result))

end

And this is the raw file:

image

How would i get the value contained in “Updates”? I would like to understand :slight_smile:

local decoded = httpService:JSONDecode(result)
print(decoded.Updates)
2 Likes

Oh it worked! Thank you! Also to you @joshuwonka!

1 Like