local M=game.Workspace.StartSpawn local n=game.Workspace.Cart local e={}local function a(M,n)local e=M.Character if e and e.Humanoid then local a=e.Humanoid if n then local n=blasterWeapon:Clone()n.Parent=M.Backpack a:EquipTool(n)else a:UnequipTools()for M,n in ipairs(M.Backpack:GetChildren())do if n.Name=="\066\108\097\115\116\101\114"then n:Destroy()end end end end end local function F(M,n,e)for M,F in ipairs(M)do if F.Character and F.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")then F.Character.HumanoidRootPart.CFrame=n.CFrame+Vector3.new(0,M*5,0)ToggleRideHUD:FireClient(F,e)a(F,e)end end end function PlayerManager.getNumberOfPlayers(M)return#e end function PlayerManager.displayEndScreen(a,M,n)for e,a in ipairs(e)do ClientEndGame:FireClient(a,M,n)end end function PlayerManager.addPlayerToGame(n,M)if not table.find(e,M)then table.insert(e,M)RideQueueUpdate:FireClient(M,"\073\078\095\081\085\069\085\069")end end function PlayerManager.movePlayersToGame(M)local a=n.PrimaryPart F(e,a,true)end function PlayerManager.removePlayersFromGame(n)local a=M F(e,a,false)e={}end return PlayerManager
-- Teleport variables
local START_AREA = game.Workspace.StartSpawn
local RIDE_PLATFORM = game.Workspace.Cart

local activePlayers = {}

local function equipTool(player, equip)
	local character = player.Character
	if character and character.Humanoid then
		local humanoid = character.Humanoid
		if equip then
			local weaponCopy = blasterWeapon:Clone()
			weaponCopy.Parent = player.Backpack
			humanoid:EquipTool(weaponCopy)
		else
			humanoid:UnequipTools()
			for _, item in ipairs(player.Backpack:GetChildren()) do
				if item.Name == "Blaster" then
					item:Destroy()
				end
			end
		end
	end
end

local function teleportPlayers(players, target, displayHUD)
	for i, player in ipairs(players) do
		-- Make sure the character exists and its HumanoidRootPart exists
		if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
			-- Add an offset of 5 for each character
			player.Character.HumanoidRootPart.CFrame = target.CFrame + Vector3.new(0, i * 5, 0)
			ToggleRideHUD:FireClient(player, displayHUD)
			equipTool(player, displayHUD)
		end
	end
end

function PlayerManager:getNumberOfPlayers()
	return #activePlayers
end

function PlayerManager:displayEndScreen(whatStatus, transitionTime)
	for i, player in ipairs(activePlayers) do
		ClientEndGame:FireClient(player, whatStatus, transitionTime)
	end
end

function PlayerManager:addPlayerToGame(player)
	if not table.find(activePlayers, player) then
		table.insert(activePlayers, player)
		RideQueueUpdate:FireClient(player, "IN_QUEUE")
	end
end

function PlayerManager:movePlayersToGame()
	local target = RIDE_PLATFORM.PrimaryPart
	teleportPlayers(activePlayers, target, true)
end

function PlayerManager:removePlayersFromGame()
	local target = START_AREA
	teleportPlayers(activePlayers, target, false)

	activePlayers = {}
end

return PlayerManager
