-- 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
