I am getting nil when trying to receive place visits for a certain game

Hello there!

I have recently tried to receive place visits for a game, with the GAMES API (roblox), I used (JSONDecode btw), But it seems it’s returning nil and I tried looking in other post’s but the solution to my problem wasn’t found.

I am using a proxy, It is called roproxy.com, and I am using HTTPService, Here’s the link I’m getting my data from: “https://games.roproxy.com/v1/games?universeIds=245662005

The script:

local httpService = game:GetService("HttpService")

local label = script.Parent.SurfaceGui.TextLabel

local URL = "https://games.roproxy.com/v1/games?universeIds=245662005"

local Data = httpService:GetAsync(URL)

local jasonTable = httpService:JSONDecode(Data)

print(jasonTable.visits)

image

The proxy is roproxy.com, It is working but, my code somehow doesn’t

What you receive is an object with the index data, which is an array with the object of the game data inside of it.

local httpService = game:GetService("HttpService")

local label = script.Parent.SurfaceGui.TextLabel

local URL = "https://games.roproxy.com/v1/games?universeIds=245662005"

local Data = httpService:GetAsync(URL)

local jasonTable = httpService:JSONDecode(Data)

print(jasonTable.data[0][0].visits)

Hm, The error now shows its attempt to index with nil, also what do you mean by what you said? if you don’t want to its fine, I’m new at http sorry xd

But I’m not sure if that’s correct…


Try this:

local httpService = game:GetService("HttpService")

local label = script.Parent.SurfaceGui.TextLabel

local URL = "https://games.roproxy.com/v1/games?universeIds=245662005"

local Data = httpService:GetAsync(URL)

local jsonTable = httpService:JSONDecode(Data)

print(jsonTable)
print(jsonTable.data[1].visits)
1 Like

It needs to be like this to actually get the visits value

print(jasonTable.data[1].visits)
2 Likes

Thank you for the correction.

1 Like

Oh whoops, yeah, it’s supposed to be a 1, not a 0, I’ve been switching between javascript, Lua, and python recently. It gets kind of confusing lol
It’s either @Katrist’s answer or

local httpService = game:GetService("HttpService")

local label = script.Parent.SurfaceGui.TextLabel

local URL = "https://games.roproxy.com/v1/games?universeIds=245662005"

local Data = httpService:GetAsync(URL)

local jsonTable = httpService:JSONDecode(Data)

print(jsonTable)
print(jsonTable.data[1][1].visits)
1 Like

Why be inconsistent with your dot notation?

JSON is similar to a table and includes string keys, so it’s better practice to access using bracket notation.


CC @MillowBro_VB

I managed to print the number of visits by accessing:

print(r["data"][1]["visits"])
1 Like

It’s more convenient for me that way; it’s really about preference, whether it’s a good practice or not. Also, you don’t always need to be consistent with that, since it would be basically forced since there’s a [1] to get the index.

Ty all so much! Here’s the final creation! (still will add stuff :D)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.