Hello, this code is returning nil:
The code is trying to get a number from a list, but the pastebin is not returning it as a list, what can I do to fix that?
Hello, this code is returning nil:
The code is trying to get a number from a list, but the pastebin is not returning it as a list, what can I do to fix that?
You are not decoding the ResponseBody
into a lua table. Right now, it’s just a json table.
Use HttpService:JSONDecode()
before storing data
. Right now, data
is just a string. Also, your pastebin will have to be formatted in JSON, where lists use [] instead of {}
would he do this:
local http = game:GetService("HttpService")
local url = "https://pastebin.com/qrc3dWnH"
local data = http:GetAsync(url)
data = http:JSONDecode(data)
print(data)
print(data[math.random(1, #data)]
sorry i really want to learn http and face my fear
Would it look like this:
local url = "https://pastebin.com/raw"
local http = game:GetService("HttpService")
local get = http:GetAsync(url)
local data = http:JSONDecode(get)
print(data)
local a = data[math.random(1, #data)]
print (a)
if so, its still giving me an error (Cant parse JSON)
You will have to modify your pastebin to use JSON instead of lua. You can learn it quickly though
How could I do this, is it ok for me to ask for a link or two on how to modify it?
Remove the comma from the last array element
Alright, everything works, thanks for the support.
can you please show your current script
Sure!
local url = ""
local http = game:GetService("HttpService")
local get = http:GetAsync(url)
local data = http:JSONDecode(get)
return data
The final problem was due to me adding an error in the actual pastebin, other than that it should work!
Oh and I am returning data because it’s a modulescript, you can just
print (data)
or store ‘data’ it doesnt matter