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!
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.
I would question why you’re doing this in the first place. It seems like a strange problem to want to solve.
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
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
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.
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.
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.
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.
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.
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:
How would i get the value contained in “Updates”? I would like to understand