Problem with simple script

Greetings

I need little bit help. I am trying to create easy and simple script, which can let players to join random games by their id. I tried to use min and max for GameIDs. I also tried everything and ran out of my ideas how to fix my script.

My script:

local function getRandomGameId(minId, maxId)
	return math.random(minId, maxId)
end

local function TeleportPlayerToGame(player, gameId)
	local success, errorMessage = pcall(function()
		local teleportService = game:GetService("TeleportService")
		local gameInfo = teleportService:GetGameInfo(gameId)

		if gameInfo and gameInfo.GameState == Enum.GameInstanceState.Started then
			local success, teleportErrorMessage = teleportService:TeleportToPlaceInstance(gameId, "", player)
			if not success then
				warn("Teleport failed: " .. teleportErrorMessage)
			end
		else
			warn("Game is not playable.")
		end
	end)

	if not success then
		warn("Error while teleporting: " .. errorMessage)
	end
end

local interactableObject = script.Parent

interactableObject.Touched:Connect(function(otherPart)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)

	if player then
		local minGameId = 100
		local maxGameId = 232424
		local randomGameId = getRandomGameId(minGameId, maxGameId)

		TeleportPlayerToGame(player, randomGameId)
	end
end)

Output: Error while teleporting: GetGamePlaceInfo is not a valid member of TeleportService “Teleport Service”

Maybe for someone It can looks like as easy problem which can be easily fixed, but I am just blind and I don’t know how.
I will appreciate any help and your advice, thank you very much in advance!

2 Likes

Don’t you think that most of the Ids that come out would be incorrect, you could use a HTTP service method that gets the games and thus REAL IDS.

3 Likes

That’s sounds good, but i don’t know how HTTP service works. I ever tried HTTP service, but i have still problems with that

1 Like

could you investigate, what I know about this service is that it is used for external things, could someone please correct me?

2 Likes

You need to use place id to teleport. To get place id you need to go to roblox studio, get asset window and open places then right click on it and copy place id and use it to teleport.


also

you mean

local mps = game:GetService("MarketplaceService")
local gameInfo = mps:GetProductInfo(gameId)
3 Likes