Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Httpservice question, how to load an external array?

Asked by 7 years ago

I am using HttpService to try to load an external array in a pastebin with user IDs but it returns a value the game reads as a whole string. I want to do this so I can dynamically add, remove, and change ranks of staff.

Not sure what I am doing wrong. Any help? I know I'm doing something wrong. I do not get an error but it prints the entire contents of the pastebin.

The script is a regular script located in ServerScriptService

[This is just part of the script, the closure is correct]

game.Players.PlayerAdded:connect(function(player)

local AdminList = {Http:GetAsync("https://pastebin.com/raw/F8fypE8N", false)} -- admin list
local ModList = {Http:GetAsync("https://pastebin.com/raw/AS0ZvPb3", false)} -- mod list
local HeadModList = {Http:GetAsync("https://pastebin.com/raw/exgyN5Xk", false)} --  list

    for i = 1, #AdminList do
        print(AdminList[i])
        if tostring(player.UserId) == tostring(AdminList[i]) then
            localRank = 1
            game:GetService("ReplicatedStorage"):WaitForChild("AdminComms"):FireAllClients(player.UserId, localRank)
        end
    end

The pastebin are in this format;

{
    26675160,
    26666928
}

Thanks if you can help!

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The problem is that your calls to GetAsync are returning single strings as opposed to tuples of strings. You should encode your pastebin text in JSON format (see below), obtain the data as a string through Http.GetAsync and then convert the string to a table using Http.JSONDecode. You will also need to convert the user IDs to numbers by using tonumber.

To make your pastebin text satisfy the JSON encoding, format it to have the same syntax as the following (you can add additional whitespace if desired):

["entry1", "entry2", "blah blah blah"]
Ad
Log in to vote
0
Answered by
HLVM 27
7 years ago
Edited 7 years ago

I heard about something called JSONDecode. I don't know much about it. But you can read the wiki: Here and here

Answer this question