Help with Github JSON Whitelist

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to edit a JSON File in Github with UserID’s like this
{
    "users":[
        1994595371,
    ],
}

and then in studio i have a script that checks when a player joins if the User Id is in that list and when not the player gets kicked.

  1. What is the issue? Include screenshots / videos if possible!
    My Issue is that everything that i try i always get an Error or also nothing that either the File cant be found or it cant be Decoded.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried everything on the Dev Forum and nothing helped me so far.

2 Likes

What’s the file? Is it a gist? Is it a file inside a repository? Is the repository public?
If you are using the URL that you see on Github in the browser’s address bar and using that to fetch the content of the file, then :JSONDecode() will fail because the URL returns HTML and not JSON. You need to use raw.githubusercontent.com

Its a .json file in a repository. If there is a better way to do it, please tell me.

You didn’t answer my other questions. Can you share the URL that you are using with HttpService?

  1. Yes the repository is public
  2. Yes i already tried raw.githubusercontent.com doesnt work too
local HttpService = game:GetService("HttpService")

local result = HttpService:GetAsync("<https://>raw.githubusercontent.com/RegisteredDeveloper/StridewayBetaTester/main/whitelisted.json")
local data = HttpService:JSONDecode(result)
local users = data.users

Remove <>, I had to add them because the forum blocks raw.githubusercontent.com URLs for some reason.

I get this error.


Share the value of result


Obviously you have to print it before calling JSONDecode() which causes the error stopping the script preventing execution from reaching the print statement.

Yeah sorry my bad. Here you go

Oh right, your file’s content is not valid JSON. In JSON there can’t be trailing commas.
immagine

1 Like

image

Now i have this how can i now make it that it checks if the user id is in that list?

JSONDecode() converts JSON objects into lua tables, so you can check like you would normally do.

if table.find(users, PlayerId) then
    -- Player is in the list
end

Hmh now i will not be kicked when i also remove my id from the list

Please use code snippets when sharing code.
```
Code goes here
```

raw.githubusercontent.com does not immediately reflect changes from the main repo. It usually takes 5 minutes.

1 Like

Ah okay thanks for this tip. Thought it will work directly. I appreciate your help!

1 Like

If it will not work in like 10 Minutes i come back okay?

Right now if you visit raw.githubusercontent.com/RegisteredDeveloper/StridewayBetaTester/main/whitelisted.json in your browser, you will see that your ID is not included.

2 Likes

Yeah tested it and it works. Thank you so much! I sat on this for 2 Days and i couldnt figure it out.

1 Like