How to make a party that teleports to a game

Hey so I was making a game where you´ll be needing parties to join a game but I don´t really understand because I´m not a scripter so I hope someone could help me

The thing I was trying to make is similar to the one from black hawk rescue mission it has a party inviter now I wanna make that but I don´t know how there should a party leader and 3 other players and need to have an invite button and they need to teleport to a game or private game is what I´ve read so if anyone could help me thanks…

7 Likes

There are a couple ways to do this. Both ways allow you to teleport a table of players.

You can either use TeleportService/TeleportPartyAsync if you are teleporting to a game with a specific Place Id and/or Job Id in a universe.

Or you can reserve a server (Private server) and teleport them with TeleportService/TeleportToPrivateServer

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
 
local code = TS:ReserveServer(game.PlaceId) -- Returns a code
local players = Players:GetPlayers() -- Get a list of all players
 
TS:TeleportToPrivateServer(game.PlaceId,code,players) -- Actually teleport the players
-- You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen

Code from the ReserveServer wiki page.

4 Likes

How do i invite players into the party?

Sorry, I was asleep when you sent that then I was at work all day. You can party players either by having them all stand in a designated area, or you can create a UI and have them click on players names to invite them to their party (Which would be stored in a table on the server) and then teleport all of them when the party leader decides to teleport them.

Like @MrLonely1221 said, you could do many things. This is called matchmaking and my goodness is this a thread that has been posted about a ton.

Please avoid posting a post if the post already exists. This is an ongoing issue on the Developer Forums.

To help with your situation however, you can have a party leader where people would get invited to it. Create all their stuff in a folder, and then teleport them when the countdown ends ( party full ) or when everyone is ready.

So, here is some help I created in about an hour.

--Client

--//Services

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

--//Variables

local Player = Players.LocalPlayer
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Parties = Assets:WaitForChild("Parties")
local MyParty = Parties:WaitForChild(Player.UserId.."'s party")
local Events = Remotes.Events
local Functions = Remotes.Functions
local UI = Assets.UI
local GUI = script.Parent
local Main = GUI:WaitForChild("Main")
local Invite = Main.Invite
local InviteCoolDown = false

--//Functions

local function CheckForPlayersYouMissed()
	for i,player in pairs(Players:GetPlayers()) do
		if Invite:FindFirstChild(player.UserId) == nil and player ~= Player then
			local Template = UI.InviteTemplate:Clone()
			Template.Parent = Invite
			Template.Name = player.UserId
			Template.Text = player.Name
			Template.MouseButton1Click:Connect(function()
				if not InviteCoolDown then
					InviteCoolDown = not InviteCoolDown
					Events:FireServer("Invite",{tonumber(Template.Name)}) -- tell the server they want to invite the player
					wait(4)
					InviteCoolDown = not InviteCoolDown
				end
			end)
		end
	end
end

local function FindInTable(index,tbl)
	for i,v in pairs(tbl) do
		if i == index then
			return v
		end
	end
end

--//Events

Players.PlayerAdded:Connect(function(player)
	if Invite:FindFirstChild(player.UserId) == nil and player ~= Player then
		local Template = UI.InviteTemplate:Clone()
		Template.Parent = Invite
		Template.Name = player.UserId
		Template.Text = player.Name
		Template.MouseButton1Click:Connect(function()
			if not InviteCoolDown then
				InviteCoolDown = not InviteCoolDown
				Events:FireServer("Invite",{tonumber(Template.Name)}) -- tell the server they want to invite the player
				wait(4)
				InviteCoolDown = not InviteCoolDown
			end
		end)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	if Invite:FindFirstChild(player.UserId) ~= nil and player ~= Player then
		Invite:FindFirstChild(player.UserId):Destroy() -- remove their stuff since they left
	end
end)

Functions.OnClientInvoke = function(Command,ArgumentTable)
	
end

Events.OnClientEvent:Connect(function(Command,ArgumentTable)
	if Command == "AddPlayerToMM" then
		local AddPlayer = ArgumentTable.Player
		local PartyPlace = ArgumentTable.PartyPlace
		Main.Party:FindFirstChild("Player"..PartyPlace).Player.Text = AddPlayer.Name
		Main.Party:FindFirstChild("Player"..PartyPlace).Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..AddPlayer.UserId.."&width=420&height=420&format=png"
		if AddPlayer == Player then
			if PartyPlace == 1 then
				Main.Ready.Visible = true
			else
				Main.Ready.Visible = false
				if Main.Party.Player1.Player.Text == Player.Name then
					Main.Ready.Visible = true
				end
			end
		end
	elseif Command == "ENDPARTY" then
		for i,v in pairs(Main.Party:GetChildren()) do
			if v.Name ~= "Player1" then
				v.Icon.Image = "rbxasset://textures/ui/GuiImagePlaceholder.png"
				v.Player.Text = "PlayerName"
			else
				v.Player.Text = Player.Name
				v.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
			end
		end
		Main.Ready.Visible = true
		Main.BadNews.Visible = true
		wait(string.len(Main.BadNews.Text)/20)
		Main.BadNews.Visible = false
	elseif Command == "Invited" then
		local PlayerFrom = ArgumentTable.From
		Main.Invited.Visible = true
		Main.Invited.Message.Text = PlayerFrom.Name.." has invited you to a party, would you like to join?"
		Main.Invited.Yes.MouseButton1Click:Connect(function()
			Main.Invited.Visible = false
			Events:FireServer("AcceptInvite",{From = PlayerFrom,Key = ArgumentTable.InviteID})
		end)
		Main.Invited.No.MouseButton1Click:Connect(function()
			Main.Invited.Visible = false
			Events:FireServer("DeclineInvite",{From = PlayerFrom,Key = ArgumentTable.InviteID})
		end)
	elseif Command == "AddAllToNewParty" then
		local PlayersTable = ArgumentTable.Players
		for i,v in pairs(Main.Party:GetChildren()) do
			local Find = FindInTable(i,PlayersTable)
			if Find ~= nil then
				if Players:GetPlayerByUserId(tonumber(Find)) == Player then
					if i == 1 then
						Main.Ready.Visible = true
					else
						Main.Ready.Visible = false
					end
				end
			end
			if Find ~= nil then
				v.Player.Text = Players:GetPlayerByUserId(tonumber(Find)).Name
				v.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Find.."&width=420&height=420&format=png"
			else
				v.Icon.Image = "rbxasset://textures/ui/GuiImagePlaceholder.png"
				v.Player.Text = "PlayerName"
			end
		end
	end
end)

Main.Ready.MouseButton1Click:Connect(function()
	Events:FireServer("Ready")
end)

--//Main

Main.Ready.Visible = true

CheckForPlayersYouMissed()

if MyParty ~= nil then
	if tonumber(MyParty.Party["1"].Value) == Player.UserId then
		Main.Party.Player1.Player.Text = Player.Name
		Main.Party.Player1.Icon.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"
	end
end

local CheckIfServerIsReserved = Functions:InvokeServer("IsReserved?")

if CheckIfServerIsReserved then
	Main.Visible = false
end
--Server

--//Services

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

--//Variables

local Assets = ReplicatedStorage:WaitForChild("Assets")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Events = Remotes.Events
local Functions = Remotes.Functions
local Parties = Assets.Parties
local AvailableStrings = {"A","a","B","b","C","c","D","d","E","e","F","f","G","g","H","h","I","i","J","j","K","k","L","l","M","m","N","n","O",
"o","P","p","Q","q","R","r","S","s","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z"}
local InviteQueue = {}

--//Functions

function FindAvailableSpot(player,joiner)
	local Done = false
	local Found = nil
	if Parties:FindFirstChild(player.."'s party") ~= nil then
		for i,v in pairs(Parties:FindFirstChild(player.."'s party").Party:GetChildren()) do
			if v.Value == "None" and not Done then
				Done = true
				Found = i
			end
			if i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and not Done then
				Done = true
				return "FULL"
			elseif i == #Parties:FindFirstChild(player.."'s party").Party:GetChildren() and Done then
				return Found
			end
		end
	end
end

local function RandomKeyMaker()
	local KeyTable = ""
	for i,v in pairs(AvailableStrings) do
		local Hello = math.random(1,2)
		if Hello == 1 then
			local RandomizedString = AvailableStrings[math.random(1,#AvailableStrings)]
			KeyTable = KeyTable..RandomizedString
		elseif Hello == 2 then
			local RandomizedNumeral = math.random(1,100)
			KeyTable = KeyTable..RandomizedNumeral
		end
		if i == #AvailableStrings then
			return KeyTable
		end
	end
end

local function ClearOriginalParty(player)
	if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
		Parties:FindFirstChild(player.UserId.."'s party").Party["1"].Value = "None"
		for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
			if v.Value ~= "None" then
				local Player = Players:GetPlayerByUserId(tonumber(v.Value))
				if Player ~= nil then
					Events:FireClient(Player,"ENDPARTY")
					if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
						if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
							Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
						end
					end
				end
			end
		end
	end
end

local function LocatePlayer(player)
	local Done = false
	for i,v in pairs(Parties:GetChildren()) do
		for _,Obj in pairs(v.Party:GetChildren()) do
			if tonumber(Obj.Value) == player.UserId and not Done then
				Done = true
				return Obj
			end
		end
	end
end

--//Events

--player added

Players.PlayerAdded:Connect(function(player)
	if Parties:FindFirstChild(player.UserId.."'s party") == nil then
		local PartyFolder = Instance.new("Folder")
		PartyFolder.Parent = Parties
		PartyFolder.Name = player.UserId.."'s party"
		local AttendeesFolder = Instance.new("Folder")
		AttendeesFolder.Parent = PartyFolder
		AttendeesFolder.Name = "Party"
		for i = 1,4 do
			if i ~= 1 then
				local X = Instance.new("StringValue")
				X.Parent = AttendeesFolder
				X.Name = i
				X.Value = "None"
			else
				local X = Instance.new("StringValue")
				X.Parent = AttendeesFolder
				X.Name = i
				X.Value = player.UserId
			end
		end
	end
end)

--player removing

Players.PlayerRemoving:Connect(function(player)
	local Find = LocatePlayer(player)
	local Send = {}
	if Find ~= nil then
		Find.Value = "None"
		for i,v in pairs(Find.Parent:GetChildren()) do
			if v.Value ~= "None" then
				table.insert(Send,tonumber(v.Value))
			end
			if i == #Find.Parent:GetChildren() then
				for _,Obj in pairs(Send) do
					local Player = Players:GetPlayerByUserId(Obj)
					if Player ~= nil then
						Events:FireClient(Player,"AddAllToNewParty",{Players = Send})
					end
				end
			end
		end
	end
	if Parties:FindFirstChild(player.UserId.."'s party") ~= nil then
		for i,v in pairs(Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren()) do
			if v.Value ~= "None" then
				local Player = Players:GetPlayerByUserId(tonumber(v.Value))
				if Player ~= nil then
					Events:FireClient(Player,"ENDPARTY")
					if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
						if Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value == "None" then
							Parties:FindFirstChild(Player.UserId.."'s party").Party["1"].Value = Player.UserId
						end
					end
				end
			end
			if i == #Parties:FindFirstChild(player.UserId.."'s party").Party:GetChildren() then
				Parties:FindFirstChild(player.UserId.."'s party"):Destroy()
			end
		end
	end
end)

--functions

Functions.OnServerInvoke = function(Player,Command,ArgumentTable)
	if Command == "IsReserved?" then
		if game.VIPServerId ~= "" and game.VIPServerOwnerId == 0 then
			return true
		else
			return false
		end
	end
end

--Events

Events.OnServerEvent:Connect(function(Player,Command,ArgumentTable)
	if Command == "Invite" then
		local PlayerToInvite = Players:GetPlayerByUserId(ArgumentTable[1])
		if PlayerToInvite ~= nil then
			local Key = RandomKeyMaker()
			Events:FireClient(PlayerToInvite,"Invited",{From = Player,InviteID = Key})
			table.insert(InviteQueue,Key)
		end
	elseif Command == "AcceptInvite" then
		local Key = ArgumentTable.Key
		local Done = false
		for i,v in pairs(InviteQueue) do
			if v == Key and not Done then
				Done = not Done
				table.remove(InviteQueue,i)
				local Spot = FindAvailableSpot(ArgumentTable.From.UserId,Player)
				if Spot ~= "FULL" then
					ClearOriginalParty(Player)
					local NewParty = Parties:FindFirstChild(ArgumentTable.From.UserId.."'s party")
					local SendTable = {}
					NewParty.Party[Spot].Value = Player.UserId
					for i,v in pairs(NewParty.Party:GetChildren()) do
						if v.Value ~= "None" then
							table.insert(SendTable,v.Value)
						end
						if i == #NewParty.Party:GetChildren()then
							Events:FireClient(Player,"AddAllToNewParty",{Players = SendTable})
						end
					end
					for i,v in pairs(NewParty.Party:GetChildren()) do
						if v.Value ~= "None" then
							local vPlayer = Players:GetPlayerByUserId(tonumber(v.Value))
							Events:FireClient(vPlayer,"AddPlayerToMM",{Player = Player,PartyPlace = Spot})
						end
					end
				end
			end
		end
	elseif Command == "Ready" then
		if Parties:FindFirstChild(Player.UserId.."'s party") ~= nil then
			local ReserveId = TeleportService:ReserveServer(game.PlaceId)
			local PlayersToTP = {}
			for i,v in pairs(Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren()) do
				if v.Value ~= "None" then
					table.insert(PlayersToTP,Players:GetPlayerByUserId(tonumber(v.Value)))
				end
				if i == #Parties:FindFirstChild(Player.UserId.."'s party").Party:GetChildren() then
					TeleportService:TeleportToPrivateServer(game.PlaceId,ReserveId,PlayersToTP)
				end
			end
		end
	end
end)

--//Main

And well, it did work but it for sure isn’t the greatest masterpiece on earth. I made this in an hour so keep in mind it could have bugs. Here is a link to the place open sourced ( also I am garbage at UI so be patient with that too… lmao );

https://www.roblox.com/games/4763336443

10 Likes

Thank you, I haven’t been able to get back here and respond to this because of work. Happy birthday btw!! :birthday:

3 Likes