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

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
