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.
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)
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)
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)
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)
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.