Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get a specific part of this HttpService GetAsync?

What I'm trying to do is to get the amount of visits in a game but whenever I try to do data.visits, it just returns nil but if I just put data by itself, it says everything. How would I exactly print only the visits?

local httpService = game:GetService("HttpService")
local url = "https://games.rprxy.xyz/v1/games?universeIds=2471084"
local res, data = pcall(function()
	return httpService:GetAsync(url, true)
end)
print(res, data.visits)

Output: true nil

1 comment

0

Answered.

1 answer

✓ Accepted answer

This returns a Encoded JSON Table, you need to decode it for use. And if you see, in Response have a table called "Data" in that table have another table that you need to open for get Information.

How to decode it? httpService:JSONDecode(Response)

How access this? DecodedJSON.data[1]

Example code:

local HttpService = game:GetService("HttpService")
local Url = "https://games.rprxy.xyz/v1/games?universeIds=2471084"
local Success, Response = pcall(function()
	return HttpService:GetAsync(Url)
end)

if Success then
	local Success, Response = pcall(function()
		return HttpService:JSONDecode(Response)
	end)
	
	if Success then
		local Information = Response.data[1]
		print("Game Visits:", Information.visits, "Max Players:", Information.maxPlayers)
	else
		print("Can't decode JSON Data")
	end
else
	print("can't get data")
end

Hope it helped! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.