local function m(m,S)m.RespawnLocation=S m:LoadCharacter()local P=m.Character or m.CharacterAdded:Wait()local j=P:WaitForChild("\072\117\109\097\110\111\105\100")setPlayerCollisionGroup(m)j.Died:Connect(function()removeActivePlayer(m)respawnPlayerInLobby(m)end)end local function S(m)local S=m.Character if S:FindFirstChild("\087\101\097\112\111\110")then S.Weapon:Destroy()end if m.Backpack:FindFirstChild("\087\101\097\112\111\110")then m.Backpack.Weapon:Destroy()end end
-- Gets the player ready by spawning them, giving them a tool, and setting up listener events
local function readyPlayer(player, whichSpawn)
	-- Reminder: LoadCharacter recreates the player, so needs to happen at the start or else tools/listeners will be lost.
	player.RespawnLocation = whichSpawn
	player:LoadCharacter()

	-- Adding in a wait to ensure player character has loaded
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")

	setPlayerCollisionGroup(player)

	-- Checks if players die
	humanoid.Died:Connect(function()
		removeActivePlayer(player)
		respawnPlayerInLobby(player)
	end)
end

local function removePlayerWeapon(whichPlayer)
	local character = whichPlayer.Character

	-- If the player has it currently on their character
	if character:FindFirstChild("Weapon") then
		character.Weapon:Destroy()
	end
	-- If theplayer has the weapon in their backpack
	if whichPlayer.Backpack:FindFirstChild("Weapon") then
		whichPlayer.Backpack.Weapon:Destroy()
	end
end
