What do you want to achieve? Keep it simple and clear!
Make a place roulette game.
What is the issue? Include screenshots / videos if possible!
A lot of times the teleport fails, and when I open the console it says “Teleport validation failed” even though the place is public and I can join it
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried making sure the games were public and there is no solutions in the Dev Hub.
local mps = game:GetService("MarketplaceService")
local ts = game:GetService("TeleportService")
local db = false
local function getRandomPlaceId(): number
local randomPlaceId = math.random(1, 999999999)
local success, info = pcall(mps.GetProductInfo, mps, randomPlaceId)
if (success == true) and (info.AssetTypeId == 9) and not string.find(info.Description, "This is your very" and "creation") and info.Name ~= info.Creator.Name.."'s Place" then
return randomPlaceId
else
return getRandomPlaceId()
end
end
local id = getRandomPlaceId()
script.Parent.Touched:Connect(function(part)
if db == false then
local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
if plr then
db = true
ts:Teleport(id, plr)
task.wait(2)
db = false
end
end
end)
Maybe because some of the places/games don’t allow teleports from other games, if they are your own game you can go to:
Roblox Studio → The Game/Place → Game Settings → Security → Allow Third Party Teleports → Enable it
For other games you can ask the owner, or developer of the game to do it, if they allow it.
TeleportService | Documentation - Roblox Creator Hub
Here is a doc on how to check for teleport service error.
You see some games might even turn on third party teleport so… I wouldn’t suggest eliminating those that don’t permanently, instead use this event that would fire if the teleport went wrong, if it did just try to find another place/game for them to teleport to.
local mps = game:GetService("MarketplaceService")
local ts = game:GetService("TeleportService")
local db = false
local function getRandomPlaceId(): number
local randomPlaceId = math.random(1, 999999999)
local success, info = pcall(mps.GetProductInfo, mps, randomPlaceId)
if (success == true) and (info.AssetTypeId == 9) and not string.find(info.Description, "This is your very" and "creation") and info.Name ~= info.Creator.Name.."'s Place" then
return randomPlaceId
else
return getRandomPlaceId()
end
end
local id = getRandomPlaceId()
script.Parent.Touched:Connect(function(part)
if db == false then
local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
if plr then
db = true
ts:Teleport(id, plr)
task.wait(2)
db = false
end
end
end)
--Addition:
ts.TeleportInitFailed:Connect(function(plr)
id = getRandomPlaceId()
ts:Teleport(id, plr)
end)
I don’t think so I know of such function, I rarely use teleportService in such a way, maybe with more research there could be one, but not that I know of within my knowledge.