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

Module API Http help? [Closed]

Asked by
Im_Nick 30
8 years ago

Im trying to get my 'module' to load into the server using Pastebin as a database. But, I don't get any errors, but I cannot yet get the 'module' ranks to insert into Ranks table.

Help?

Database : http://pastebin.com/EiFyEHzr

Any help would be nice :)

My output from print(#Ranks) = 0

local Ranks = {}
local url = "http://pastebin.com/raw/EiFyEHzr" -- (raw data)
local http = game:GetService("HttpService")

function update()
    print(Ranks)
    local html = loadstring( http:GetAsync(url, true) )()
    if type(html) == "string" then
        local json = http:JSONDecode(html)
        if type(json) == "table" then
            for index = 1,#Ranks do
                table.remove(Ranks, index)
            end
            for _,v in next,json do
                print(v.User, v.Details)
                table.insert(Ranks, v)
            end
        else
            print("Not a table!")
        end
    end
end

update()
print(#Ranks)
table.foreach(Ranks, print)

1 answer

Log in to vote
1
Answered by 8 years ago

You're returning a table

I'd advise keeping pure JSON in the paste instead of Lua code, as it introduces fewer vulnerabilities.

0
Ah, Thank you! Im_Nick 30 — 8y
Ad

Answer this question