How to make a group of players to another game

Hello! So I know there are videos on this but none of them helped me. I’ve also looked at other Dev Forum posts and those didn’t help either.
So what I’m trying to do is, so like a group of people get into a van and a few seconds later the van drives away and teleports only the players in the van to a place inside of a place (Or as I call them, “Sub Games”).
I figured I would use ReserveServer() but couldn’t figure out how I would do a few things:

A. Make a table of the players who are in the van.
And B. Teleport those players to the Sub Game via ReserveServer()

Here is my code:

local TweenService = game:GetService("TweenService")
local Van = script.Parent.VanBody

local info = TweenInfo.new(
    5,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    true,
    0
)

local Goal = {
    Position = Vector3.new(-34.534, 6.244, 23.164)
}

local NewTween = TweenService:Create(Van, info, Goal)

while wait(3) do
    if script.Parent.AmountOfPlayers.Value >= 1 then -- Will be later changed to 3
	    NewTween:Play()
	
	    --Disable Pad

	    script.Parent.Pad.Script.Disabled = true

	    wait(5)
	    print("Teleporting Players...")

	    --Teleport Players
	
	    local TeleportService = game:GetService("TeleportService")
	    local PlaceID = 123456789
	
	local Players = { }
	
	script.Parent.Pad.Touched:Connect(function(hit)
		
		local PlayerWhoTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
		table.insert(Players, 1, PlayerWhoTouched)
		
	end)
	
	local Code = TeleportService:ReserveServer(PlaceID)
	
	for i, v in pairs(Players) do
		
		TeleportService:TeleportToPrivateServer(PlaceID, Code, {v})
		
	end

	wait(5)

	-- Renable the pad

	script.Parent.Pad.Script.Disabled = false
	
	script.Parent.AmountOfPlayers.Value = 0
	
    end
end

Thanks for the help and sorry for the trouble!

P.S. I’m not sure if this matters but I’m also trying to make it so it only teleports if there is at least 3 players and at most 5 players in the van.

TeleportToPrivateServer supports a list of players to be teleported to a place. If you’re already making a table of players who should be teleported then pass that instead of iterating over it and teleporting each one of them individually.

Specifically, change your teleport line to this:

TeleportService:TeleportToPrivateServer(PlaceID, Code, Players)

The rest of your code looks mostly fine except for that while wait line which is scary not just because you’re using wait as your while loop’s conditional but also because you’re connecting signals in that loop. That’s a nice ticket to a memory leak.

Regarding the van player check, you can always check through existing players and see if they are seated in the van by checking what SeatPart they’re on and if said SeatPart is part of the van. You could also check if players are in the vicinity of the van. Many things you can do there.

In terms of your second question, you already figured that out in your code and even wrote it down, so what specifically do you need help on there? I mean, other than the fact that you haven’t changed the PlaceId. If what you wanted was dynamic PlaceIds, you can use an attribute on the van to determine which place the players should be going to and define PlaceId as the van’s PlaceId attribute.

Oh I apologize that is old code. Here let me get the new code.

local TweenService = game:GetService("TweenService")
local Van = script.Parent.VanBody

local info = TweenInfo.new(
	5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	0
)    

local Goal = {
	Position = Vector3.new(-34.534, 6.244, 23.164)
}    

local NewTween = TweenService:Create(Van, info, Goal)

while true do
	if script.Parent.AmountOfPlayers.Value >= 1 then
		NewTween:Play()
		
		--Disable Pad

    	script.Parent.Pad.Script.Disabled = true

    	--script.Parent.Pad.Script.Disabled = true	

    	wait(5)
    	print("Teleporting Players...")

    	--Teleport Players
    	
    	local TeleportService = game:GetService("TeleportService")
    	local PlaceID = 6428301658
    	
    	local Players = {}
    	
    	script.Parent.Pad.Touched:Connect(function(hit)
    		
    		if hit.Parent:FindFirstChild("Humanoid") then
    			local PlayerWhoTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
    			table.insert(Players, 1, PlayerWhoTouched)
    		end
    		
    	end
    	
    	if Players ~= nil then
    		TeleportService:TeleportPartyAsync(PlaceID, Players)
    	end
    		

    	wait(5)

    	-- Renable the pad

    	script.Parent.Pad.Script.Disabled = false
    	
    	script.Parent.AmountOfPlayers.Value = 0
	
    end
    wait(3)
end

I wasn’t sure if I should use ReserveServer() or TeleportPartyAsync() so I went with TeleportPartyAsync()
And also there are no seats, they are just standing in the van. Sorry if I confused you.

If you want I can send a video of what I’m trying to achieve.

Thanks for the help!

TeleportPartyAsync does not support matchmaking and private servers so this is probably not what you want to use. If new players were teleported to the place, they would join another server’s ongoing round and that might be awkward if your code doesn’t handle that.

Determining which players are sitting in the van (that’s your players table and the Pad touch) should be divorced from your while loop. Other than that, you’ve pretty much got down the basics of how to accomplish this system. Since it seems like you have multiple copies of this script, divorcing the player collector from the player check seems sufficient enough. Notably, part of your problem might be that the players table is local to the scope of the while loop so it keeps “refreshing”.

This is dummy code so it’s meant for learning, not copying and pasting, so I’ve opted to write some parts in pseudocode instead of real code. If it does not work, this’ll tell you why. I’m expecting that you do a bit of research to turn the pseudocode into real code.

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

local Van = script.Parent.VanBody
local Pad = script.Parent.Pad

local TWEEN_INFO = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true)
local GOAL = {Position = Vector3.new(-34.534, 6.244, 23.164)}

local LEAVE_TWEEN = TweenService:Create(Van, TWEEN_INFO, GOAL)

local playersInVan = {}

LEAVE_TWEEN.Completed:Connect(function ()
    -- In case the van table didn't properly clear, do it again
    if #playersInVan > 0 then
        table.clear(playersInVan)
    end
    -- Reenable the pad, but don't use the Disabled property of scripts
    -- You should virtually never do that in production-level code
end)

Pad.Touched:Connect(function (hit)
    -- Make sure player is not in playersInVan table; if they aren't, add them
end)

while true do -- Would use RunService instead, in my honest opinion
    -- # of players greater than 1?
        LEAVE_TWEEN:Play()
        -- Disable pads
        -- Have some way to get a placeId here
        local reserveCode = TeleportService:ReserveServer(placeId)
        TeleportService:TeleportToPrivateServer(placeId, reserveCode, playersInVan)
        table.clear(playersInVan)
        -- Wait a bit, reenable pads

This is at the end of the round. So they are going into the lobby after a round. Sorry if I wasn’t clear before. :neutral_face:

wait ignore that post :neutral_face: I got it mixed up. It is going into the round.

Oh, gotcha. The part that wasn’t clear was where they were going, but it was me who didn’t catch at the end that players do not actually sit in the van. In this case, TeleportPartyAsync would be the go-to method for teleporting them back.

I think the pseudocode I provided in the post above would still work for your use case, just that it’d have nothing to do with reserving private servers. The general idea is what you want to divorce the gathering of who’s in the van from your while loop.

Ignore that last post. I got it mixed up. I am trying to get them into the round. I’m very sorry I’m tired and can’t think straight right now.

I’m usually not this bad at communication, my brain just isn’t working right now. I’m so sorry about this.

Hello I just tested it out. (Yes I replaced the pseudocode) And it didn’t work. I’m not sure if I’m doing something wrong (Probably am)
I’m very sorry for the trouble.
Thanks!

Here is the code:

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

local Van = script.Parent.VanBody
local Pad = script.Parent.Pad

local TWEEN_INFO = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, 
true)
local GOAL = {Position = Vector3.new(-34.534, 6.244, 23.164)}

local LEAVE_TWEEN = TweenService:Create(Van, TWEEN_INFO, GOAL)

local playersInVan = {}

LEAVE_TWEEN.Completed:Connect(function ()
    -- In case the van table didn't properly clear, do it again
    if #playersInVan > 0 then
    	table.clear(playersInVan)
    end
	-- Reenable the pad, but don't use the Disabled property of scripts
    -- You should virtually never do that in production-level code
    Pad.Script.Disabled = false
end)

Pad.Touched:Connect(function (hit)
    -- Make sure player is not in playersInVan table; if they aren't, add them
    if hit.Parent:FindFirstChild("Humanoid") then
    	table.insert(playersInVan, game.Players:GetPlayerFromCharacter(hit.Parent))
    end
end)

while true do -- Would use RunService instead, in my honest opinion
	if #playersInVan >= 1 and #playersInVan < 5 then
	    -- # of players greater than 1?
    	LEAVE_TWEEN:Play()
        -- Disable pads
	Pad.Script.Disabled =  true
	local placeId = 6428301658
	local reserveCode = TeleportService:ReserveServer(placeId)
	TeleportService:TeleportToPrivateServer(placeId, reserveCode, playersInVan)
	table.clear(playersInVan)
	-- Wait a bit, reenable pads
	--Pad.Script.Disabled = false
end
wait(1)
end

Hi, I recently had a problem like this trying to make a multiplayer survival game. I found the answer to my problem by a thread made here on the dev forum, heres the link :smiley:

The solution to your problem is the solution to the thread I showed you. I would just send the rblx link so you can just download the game, but that would be taking credit for other people’s work, sorry.

Hello! Thanks for responding. I got it to work a little bit ago. Sorry for making you go out of your way.
Thanks!