How to make my script teleport the player to my friends game?

Collab with my friend

I get an HTTP 400 Bad Request

Everything :frowning:

I am trying to make a collab with my friend but it wont work, I used reserveServer and TeleportToPrivateServer, I did this from a serverscript also this goes through all players is this correct or do I do {player} instead of {players}

local TS = game:GetService("TeleportService")

local players = game.Players:GetPlayers()
script.Parent.Touched:Connect(function(h)
    local player = game.Players:GetPlayerFromCharacter(h.Parent)

    if player then
        local code = TS:ReserveServer(myfriendgameID)

        TeleportService:TeleportToPrivateServer(myfriendgameID,code,{players})
    end
end)

I would appreciate help

I assume you are trying to teleport the player who touched the parent, if so, it should just be {player} as you are trying to teleport the player who touched it.

1 Like

I did that and I still get the same reaction

Thanks for the help though :frowning: (Eeeeeeeeeeeee)

I think you need to use TeleportService:GetPlayerPlaceInstanceAsync() then use TeleportService:TeleportToPlaceInstance()

hope this helps, if you have any questions let me know.

You cannot reserve servers in other peoples games
use
TeleportService:Teleport() or TeleportService:TeleportAsync() instead

2 Likes

How do I use these two functions? @Motofied

How do I use TeleportAsync ? The Wiki [developer.roblox.com] didnt help is it like :Teleport but different??

I tried GetPlayerPlaceIdAsync or whatever it was it wont work

https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportAsync
‘This function serves as the all-encompassing method to teleport a player or group of players from one server to another.’
Example:

local TeleportService = game:GetService('TeleportService')

TeleportService:TeleportAsync(PlaceId, {plr1, plr2, plr3})

This will teleport plr1, plr2 and plr3 all to the given game
The difference between TeleportAsync and Teleport is that TeleportAsync can teleport multiple players at once where Teleport can only do one at a time

@anthropomorphic_dev Would this work?

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

local ServerAccessCodes = DataStoreService:GetDataStore("ReservedServerAccessCodes")

-- Teleport the player to a reserved server
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true

script.Parent.Touched:Connect(function(h)
	local player = game.Players:GetPlayerFromCharacter(h.Parent)
	
	if player then
		local teleportResult = TeleportService:TeleportAsync(MYFRIENDSGAMEID, {player}, teleportOptions)

		-- Save the ReservedServerAccessCode from the TeleportResult instance
		ServerAccessCodes:SetAsync(teleportResult.PrivateServerId, teleportResult.ReservedServerAccessCode)

		-- To retrieve the access code (can only be done from in the reserved server)
		local accessCode = game.PrivateServerId ~= "" and ServerAccessCodes:GetAsync(game.PrivateServerId)
	end
end)

No it won’t. As I stated above

Use :Teleport() if you’re teleporting one player and :TeleportAsync() if you’re teleporting multiple(Like a party of players)

Oh okay well if I use Teleport theres a problem it wont work I will show the code of it

@anthropomorphic_dev

local Teleportservice = game:GetService("TeleportService")

script.Parent.Touched:Connect(function(h)
	local plr = game.Players:GetPlayerFromCharacter(h.Parent)
	
	if plr then
		Teleportservice:Teleport(friendgameid,plr)
	end
end)
1 Like

Will that work? Or no will that not work at all

Did a quick test and it works fine so it should be good for you

Do I need to own the game??/ b this is what i did the first time and it bugged ima test it

You should not need to own the game you’re teleporting too no
One thing you do need is to have ‘Allow Third Party Teleports’ enabled in the game settings
Its in Game Settings > Security

1 Like

So it says it is restricted to teleport to it