How to make a random game finding script

I want to make a script in which it searches for random games on roblox, and make it so if the player wants to play that, it will Teleport him to the game shown. Is there any way this is possible?

TeleportService is how you transport players to different experiences. However, searching randomly is complicated because it uses PlaceIDs, which is a set of numbers. So randomly generating a set of numbers is a hit or miss as to whether it will be a valid game ID or not.

1 Like

Yes, teleporting players I can do, and you are correct, searching for valid game id’s are difficult. But I have seen a game done it and I would want to know how to do it if anyone knows

math.random can pick random numbers , I already made one of these and it worked well

1 Like

That’s true, but I would have to make an entire list of game ids. I want it to randomly find game ids, and choose any random game id that exists.

Protected call on MarketplaceService:GetProductInfo().AssetTypeId. You should match this to AssetType enum to decide whether you’ve found a real experience.

You can generate random IDs (Random object or math.random) until your pcall returns successfully.

1 Like

math.random(1,999999) would pick you random games.

1 Like

So the basic premise of a random game finder is to get a number from 1 to your prefered number for example 9999999, and it will return a random number from 1 to 9999999, the you basically teleport the player using TeleportService to the specified number. Here is a quick example:

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

Players.PlayerAdded:Connect(function(Player)
   if Player then
      TeleportService:Teleport(math.random(1, 9999999), Player) --// actually teleport the player
   end
end)
2 Likes
local games = {1 , 2}  -- Your desired game Ids 
local TeleportService = game:GetService("TeleportService") 
for _ , player in pairs(game.Players:GetPlayers()) do -- :GetPlayers() method returns table consistng every player instance in the game through which we loop and teleport to a random game.
    local ChosenGame = games[math.random(1,#games)]  -- Picks a random Id out of the table
    TeleportService:Teleport(ChosenGame,player)  -- Takes in arguments of (gameId,Player) and 2 optional arguments which were not included here.
end

Loops through every player in the game and teleports them to random game chosen.
If you do not get anything in the script just ask.

1 Like

It works, thanks for helping me.