Roblox Random Game Teleporter help

Hello,

I want to make a script that randomly teleports a user to a roblox game, as long as its valid as shown:

local TeleportService = game:GetService("TeleportService")
local HttpService = game:GetService("HttpService")

local maxUniverse = 10000000000
local ranges = {
	{0, 2000000000}, {2000000001, 4000000000}, {4000000001, 6000000000},
	{6000000001, 8000000000}, {8000000001, 10000000000}
}
local size = 50
local ratelimit = 1 

local function getRandomUniverse()
	local range = ranges[math.random(1, #ranges)]
	return range[1] + math.random(0, range[2] - range[1])
end

local function getPlaceIdsFromUniverses(universeIds)
	if #universeIds == 0 then return {} end
	local placeIds = {}
	
	local data
	local success, response = pcall(function()
		local url = "https://games.roproxy.com/v1/games?universeIds="..table.concat(universeIds, ",")
		data = HttpService:GetAsync(url)
	end)
	if success and data then
		local info = HttpService:JSONDecode(data)
		for _, gameData in ipairs(info.data) do
			if gameData.rootPlaceId then
				table.insert(placeIds, gameData.rootPlaceId)
			end
		end
	end
	return placeIds
end

local function filterPlayableUniverses(universeIds)
	if #universeIds == 0 then return {} end
	local playable = {}
	
	local data
	local success, response = pcall(function()
		local url = "https://games.roproxy.com/v1/games/multiget-playability-status?universeIds="..table.concat(universeIds, ",")
		data = HttpService:GetAsync(url)
	end)
	if success and response then
		local info = HttpService:JSONDecode(response)
		for _, universe in ipairs(info) do
			if universe.isPlayable then
				table.insert(playable, universe.universeId)
			end
		end
	end
	return playable
end

local function teleportRandomPlayer(player)
	local teleported = false
	while not teleported do
		local universeBatch = {}
		for i = 1, size do
			table.insert(universeBatch, getRandomUniverse())
		end

		local playableUniverses = universeBatch--filterPlayableUniverses(universeBatch)
		local playablePlaces = getPlaceIdsFromUniverses(playableUniverses)

		if #playablePlaces > 0 then
			local chosenPlace = playablePlaces[math.random(1, #playablePlaces)]
			local success, err = pcall(function()
				TeleportService:TeleportAsync(chosenPlace, {player})
			end)
			if success then
				teleported = true
			else
				warn("Teleport failed: "..tostring(err))
			end
		end

		task.wait(ratelimit)
	end
end

local running = false
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if not running then
			running = true
			teleportRandomPlayer(player)
		else
			return
		end
	end
end)

I don’t know if theres a better way to do this, but it goes through and finds a random universe ID using ranges. It checks each universe to find which ones are playable. Then it uses roproxy to get the placeIDs from universe IDs. It will teleport the user to the place IDs after.

However, when checking isPlayable, roproxy always returns false since I am not authorized, any other ways to do this? Or is there a direct fix?

I’m not sure this is possible.. Randomly generating universe IDs will almost never hit a valid, playable game. A practical solution is to maintain a predefined list of Place IDs that are known to work and pick one at random. At least you could maintain a quality pick that way.

The main thing is, I want to find a COMPLETELY random game on roblox, out of every single one. Also, this generates 100 at a time and will wait the ratelimit (1-5 seconds probably), which means it should work eventually after some time.

The main issue is with roproxy and authentication.

I saw that. Good luck with 10–12 digits. It will be easier to pick the winning lotto numbers than that.

So would there be another way to randomly pick a roblox game, like how other ones do it?

Like I said, go find a bunch of them, pick some quality ones, and randomize them.
Research killed that..

You’ll most likely still have problems reliably teleport players into games you don’t own.
If the games are part of a team creation or collaborative group, then yes, you can teleport players to them.

1 Like

I mean, I see your point, and that would definitely work under normal circumstances. The main thing is about roproxy’s authentication, is there any way around that? It always returns isPlayable as false.

I wouldn’t even try that.. Honestly
The ones you see with a bunch of different games like that are most likely set to collaborative.

It’s based on universe ID though, and all I’m looking for is experiences that the user can join.
Sorry if I’m misunderstanding you.

I guess you could do it like that.. again you would be back to a list to pick from.
Roblox does not provide a public API to search every universe by ID..

Yeah but since its based on universe ID theres a good chance it’ll find a teleportable game. I can also filter out starter places later on.

The main thing I’m worried about is finding if its playable, I know the multiget-place-status and details have that.

womp womp. I’m getting close however

1 Like

The main thing I’m worried about is finding if its playable, I know the multiget-place-status and details have that.

Why does it matter? Just keep attempting to teleport the player until it’s successful

It then results in lots of errors, one of them I haven’t found a fix for (error code 773, attempt to teleport to a restricted place) - the server code doesn’t detect it.
Is there a way to do that? If so, that would be great!

Thats basically whats happening.

Yeah, I sent my current script in the OG post.

If you add a small wait in between teleport requests, they should still go through even if one of them isn’t playable and gives an error code 773, although a time delay might make the wait to find a playable place id a little long.

Since roproxy always returns isPlayable = false, you could create your own API and use httpservice to let it make the request for you with your own auth cookies, just remember to respect api rate limits

@txclove I think I found a workaround, but thanks for the help!
@2112Jay I made some code to get every single working UniverseID, but thanks so much for the code! I’ll remember to credit you.

I was getting there .. Think I almost had it.
Can you send me that list or a few of them to test with. I’m not done yet. Even if you are..

I keep getting


Please don’t credit me when I’m failing. I have to earn that.
Good puzzle here. Something I’ve never tied.

Well this is easy with my games, clearly it works.. The games have to be open
and there is no good list I can find. (yet)

Yeah that’s the main issue I’m trying to get around with isPlayable.
It works with a list of working games.