How to know how many players are being teleported?

Hi! I am making a game, there are like rooms where countdown goes from 30 to 1 and it teleports player which stay on the circle. SO it teleport to main game from lobby (like Doors) but in the main game i need to know if all the players are on the server so i already tried to use teleport options and now i found out that i can use cross-server messaging, so how can i get like special session id or idk. I just need this message to send to certain server. I’ve already tried using jobId, placeId, PrivateServerId and as i said - TeleportOptions. hope u understood

lobby script:

local TS = game:GetService("TeleportService")
local MS = game:GetService("MessagingService")
local TweenService = game:GetService("TweenService")
local placeId = 134738479021365
local events = game.ReplicatedStorage.Assets.Remotes.Events
local leaveGuiEvent = events.LeaveEvent
local TransitionEvent = events.FadeEvent
local list = {}
local gui = script.Parent.Barrier.SurfaceGui
local billboard = script.Parent.Billboard.billboardGui
local timer
local teleporting = false
local spawnTeleport = script.Parent.Teleport

local function updateGui()
	gui.Frame.players.Text = #list
	billboard.Frame.players.Text = #list
end

local function removeFromList(character)
	for i=1,#list do
		if list[i] == character.Name then
			table.remove(list,i)
			updateGui()
		end
	end
end

local function teleportPlayers()
	if #list > 0 then
		script.Parent.Barrier.SurfaceGui.Frame.Status.Text = "TELEPORTING"
		script.Parent.Barrier.SurfaceGui.Frame.Status.TextColor3 = Color3.new(1,0,0)
		local playersToTeleport = {}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		local code = TS:ReserveServer(placeId)
		teleporting = true
	
		TS:TeleportToPrivateServer(placeId, code, playersToTeleport)
		repeat wait() until #list <= 0
		--MS:PublishAsync(, playersToTeleport)
		script.Parent.Barrier.SurfaceGui.Frame.Status.Text = "READY"
		script.Parent.Barrier.SurfaceGui.Frame.Status.TextColor3 = Color3.new(34/255,255/255,20/255)
		teleporting = false
	end
end

script.Parent.Barrier.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false
			
			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end
			
			if alreadyExists == false then
				if #list < 16 then
					table.insert(list,char.Name)
					char.PrimaryPart.CFrame = spawnTeleport.CFrame
					updateGui()
					leaveGuiEvent:FireClient(player)
				end
				
				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end
			
		end
	end
end)

leaveGuiEvent.OnServerEvent:Connect(function(player)
	if player.Character then
		player.Character.HumanoidRootPart.Anchored = false
		wait()
		player.Character.Humanoid.Jump = true
		removeFromList(player.Character)
		player:LoadCharacter()
	end
end)

while wait() do
	timer = 30
	for i=1,timer do
		timer = timer - 1
		gui.Frame.time.Text = timer
		billboard.Frame.time.Text = timer
		wait(1)
	end
	teleportPlayers()
end

main game script

local plrs = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local msgService = game:GetService("MessagingService")

local remotes = replicatedStorage:WaitForChild("Remotes")

local module = {}

msgService:SubscribeAsync(game.JobId, function(plrs)
	print(plrs)
end)

return module

Maybe this will help. In your teleport data, you’d write down how many players there are before teleporting them.

i’ve already tried it. teleport data returns nil and idk how to fix that

do #plrs, itll return how many there are

huh? i need to know how many players are being teleported so server will wait untill #players:GetChildren() == amount . I mean i dont need to know how many players on the server, i need to know how many are being teleported from lobby to main game

maybe send some teleportation data?

uhh i already said that it returns nil in main game when im trying to send ANY data - numbers, strings, tables

alr i used teleport data. The reason it didnt work - i used wrong parameters

local teleportData = {
			amount = #playersToTeleport
		}

TS:TeleportToPrivateServer(placeId, code, playersToTeleport, "", teleportData)
-- i forgot to mention "" as spawn name before the teleport data

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.