How to check if a game is a place or a game

so i want to make a game that teleports you to other random games but theyre often just some sub-places to other games
image
image
is it possible to somehow check if the generated id is a game or a place to prevent this from happening?

So this is a game working as a portal to random places?
Those IDs are generated randomly?
Sometimes you get the subplace instead of the StartingPlace/Game ID?

To get the startingPlace of a game when only having a subplace ID you could do an HTTP GET request to the following URL: https://api.roblox.com/marketplace/productinfo?assetId=<ASSET ID>

The response will be in JSON format, and it will contain a field called ProductId . The value of this field is the game ID of the starting place that the subplace is a part of.

local HttpService = game:GetService("HttpService")

local assetId = 123456 -- The generated ID
local url = "https://api.roblox.com/marketplace/productinfo?assetId=" .. assetId
local response = HttpService:GetAsync(url)
local data = HttpService:JSONDecode(response)
local gameId = data.ProductId

yeah that would work too, but wouldnt that end up with 50% of the teleports being notoriety, tower battles or some other popular game?
is it possible to get a boolean that would tell me wheter its a game or a subplace so i can ignore them?

Im not sure, maybe like this:

local placeId = 12345 -- Replace with the Place ID you want to check

local response = game:GetService("HttpService"):GetAsync(
  "https://www.roblox.com/api/place/get-place?placeId=" .. placeId
)

local data = game:GetService("HttpService"):JSONDecode(response)

if data.parent then
  print("This is a subplace.")
else
  print("This is a starting place.")
end

nope it gave me this error
image

What about:

local placeId = 12345 -- Replace with the Place ID you want to check

local response = game:GetService("Networking"):PostAsync(
  "https://www.roblox.com/api/place/get-place",
  "application/x-www-form-urlencoded",
  "placeId=" .. placeId
)

local data = game:GetService("HttpService"):JSONDecode(response)

if data.parent then
  print("This is a subplace.")
else
  print("This is a starting place.")
end


apparently theres no such thing as PostAsync

I like the game idea you have, if you make it work properly give priority to my games :3 haha.
Is Networking enabled for your experience?

if game:GetService("Networking") then
  print("The Networking service is available.")
else
  print("The Networking service is not available.")
end

Honestly I never tried your request before… does the other games needs to have it enabled it too? idk…

image
nope it is not, how would i enable it?

Did you ever solve the issue? I have the same problem

I found a solution!

Not sure if there’s a better way to do this, but here’s what I’ve come up with :

local httpService = game:GetService("HttpService")

function isPlace(id)
	local universeId = httpService:JSONDecode(httpService:GetAsync(`https://apis.roproxy.com/universes/v1/places/{id}/universe`)).universeId
	local universeInfo = httpService:JSONDecode(httpService:GetAsync(`https://games.roproxy.com/v1/games?universeIds={universeId}`)).data[1]
	return universeInfo.rootPlaceId ~= id
end

It uses roproxy because Roblox doesn’t allow you to make requests to roblox.com via HttpService.

You could also make the function return the original starting place instead so that you won’t have to move onto a new random ID every time.

2 Likes

it works but sometimes i get HTTP 400 (Bad Request) in the output

It’s because it relies on http requests which can sometimes fail for whatever reason - Not sure if there’s a better way to achieve this.

You could try wrapping the code in a pcall to catch errors and retry the request a set amount of times.

1 Like