Random game teleporter help?

I’ve created a random place teleporter that works, my problem is I think it’s either selecting ones that are closed or ids that just don’t exist at all. I keep getting this error image

How can I change this so it will only select open and existing games? Here is my teleport generation code

teleporter = game.Workspace.Teleport
local PlaceID = teleporter.PlaceID

button.ClickDetector.MouseClick:Connect(function(clicked)
	teleporter.Active.Enabled = false
	teleporter.boot:Play()
	teleporter.BrickColor = BrickColor.new("Smoky grey")
	PlaceID.Value = math.random(1, 98000000)
	wait(1.7)
	teleporter.BrickColor = BrickColor.new("Institutional white")
	teleporter.Active.Enabled = true
	wait(0.1)
end)

Try using pcall function first, if it work. Then Teleports the player if it doesnt, retry

1 Like

Use this to determine whether or not a teleport was successful, if it wasn’t then attempt to perform the teleportation again with a new randomly generated ID.

Can you share the script where the teleportation is performed?

	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		game:GetService("TeleportService"):Teleport(script.Parent.PlaceID.Value, game.Players[hit.Parent.Name])
	end
end)

Is this all in the same script (will make it easier), provide the full thing if you can.

It’s not in the same script because I have the teleport one inside a part, you have to touch it to teleport

Can you move the teleporting to the same script? Since if a teleport fails you’ll need to generate a new number. You could use a bindable event to communicate between the 2 scripts but that seems like unnecessary effort.

you can use a proximity prompt too!
proximity prompt have a triggered which contain a variable called “player”
the player i mean is a player instance which triggered a proximity prompt!

I already read the teleport results but I never use it before so I dont understand it much!

however, If you can try the pcall function. That will be great!

local success,error = pcall(function()
teleporter:Teleport(randomplaceid,player)
end)
if success then
--I think it auto tp so dont worry about it
elseif error then
print(error)
--this line, you'll have to make a new random number generation and do a tp again
end

Currently, im busy so I cant help you much!

Isn’t there just a way to find out if the game is open or not and regenerate if it isn’t a lot of these games do something like that

local teleporter = workspace:WaitForChild("Teleport")
local PlaceID = teleporter.PlaceID
local button = script.Parent
local part = workspace:WaitForChild("Part")
local tps = game:GetService("TeleportService")
local players = game:GetService("Players")

button.ClickDetector.MouseClick:Connect(function(player)
	teleporter.Active.Enabled = false
	teleporter.boot:Play()
	teleporter.BrickColor = BrickColor.new("Smoky grey")
	PlaceID.Value = math.random(1, 99999999)
	task.wait(1)
	teleporter.BrickColor = BrickColor.new("Institutional white")
	teleporter.Active.Enabled = true
end)


part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local id = script.Parent.PlaceID.Value
			tps:Teleport(id, player)
		end
	end
end)

tps.TeleportInitFailed:Connect(function(player, res, err)
	PlaceID.Value = math.random(1, 99999999)
	if player then
		local id = script.Parent.PlaceID.Value
		tps:Teleport(id, player)
	end
end)

Fix the reference to the “part” which is touched if necessary. You may need to add a temporary delay (if teleporting has limits).

You could but you’d need to setup HttpService & a proxy to issue requests to Roblox’s API endpoints.

Hello!

I had the same problem but i got the problem solved!

Basically you use a pcall to check if the placeID really exists, If not, repeat the process until you find a game that is actually playable.

I do have a code for this kind of situation. Maybe you could merge it with yours?

local TeleportService = game:GetService("TeleportService")
local ChoosenID = 0

function IsGameValid(id)
	local isgame

	local success,message = pcall(function()
		ChoosenID = id
	end)

	return success and ChoosenID
end 

function GetRandomGame()
	local RandomID = math.random(1, 1000000000) 
	print(RandomID)
	IsGameValid(RandomID)
end

if IsGameValid(ChoosenID) then
	local GameID = game:GetService("MarketplaceService"):GetProductInfo(ChoosenID)
	TeleportService:Teleport(ChoosenID, game.Players:GetPlayers())
else
	GetRandomGame()
end

It’s a serverscript so, Yeah.