I made this script for a block to only take away 1 or 2 tools called "Sword" and "Water Bottle" and if they have 3 tools it only takes the Sword and the Water Bottle away. What is wrong with my script it takes the whole inventory away, and how could I fix it?


keepers = {"berezaa"}

-- These are customizeable criteria regarding exactly what is removed, and where it is removed from:
RemoveTools = true
RemoveHopperBins = true
RemoveFromBackpack = true
RemoveFromCharacter = true
RemoveForceField = false

script.Parent.BrickColor = BrickColor.new(21)

function getPlayer(humanoid)
	local players = game.Players:GetChildren()
	for i = 1, #players do
		if (players[i].Character.Humanoid == humanoid) then return players[i] end
	end
	return nil
end

function checkKeeper(player)
	for i = 1,#keepers do
		if (keepers[i] == player.Name) then return true end
	end
	return false
end

function RemoveWeapons(parent)
	local weapons = parent:GetChildren('Sword')
	for i = 1,#weapons do
		if (weapons[i].className == "Tool") and (RemoveTools == true) then
			weapons[i]:remove()
			script.Parent.BrickColor = BrickColor.new(22)
		elseif (weapons[i].className == "HopperBin") and (RemoveHopperBins == true) then
			weapons[i]:remove()
			script.Parent.BrickColor = BrickColor.new(22)
		end
	end
end

local debounce = false

function onTouched(hit)
	local human = hit.Parent:findFirstChild("Humanoid")	
	if (human == nil) then return end
	local player = getPlayer(human)
	if (player == nil) then return end

	if (checkKeeper(player) == true) or (debounce == true) then return end

	debounce = true

	if (RemoveFromBackpack == true) then
		local backpack = player.Backpack
		if (table.maxn(backpack:GetChildren()) > 0) then
			RemoveWeapons(backpack)
		end
	end
	
	if (RemoveFromCharacter == true) then
		RemoveWeapons(player.Character)
	end
	
	if (RemoveForceField == true) then
		local charparts = player.Character:GetChildren()
		for i = 1,#charparts do
			if (charparts[i].className == "ForceField") then
				charparts[i]:remove()
				script.Parent.BrickColor = BrickColor.new(22)
			end
		end
	end

	wait(0.5)

	script.Parent.BrickColor = BrickColor.new(21)
	debounce = false
end

script.Parent.Touched:connect(onTouched)

-- Goldenkings11