IF a player has more than One Tool then

I wanted to Know If there was A way To check If the Player has More than One Tool In Their Backpack.

Use it:

local playerHasMoreThanOneTool = #player.Backpack:GetChildren() > 1
print playerHasMoreThanOneTool
3 Likes

Thanks I will try that :slight_smile: right now

1 Like

I would make an array

Local Backpack = player.Backpack:GetChildren()

if #Backpack ~= 1 then
   — code
End 
1 Like

I tried this but It made an error. Anything wrong with my script?

local part = script.Parent

part.Touched:Connect(function()

local player = game.Players.LocalPlayer
local Backpack = player.Backpack:GetChildren()

if #Backpack ~= 1 then
	
	print("Wow")
	end 

end)

Are you putting it inside a local script or server script?

local function GetNumOfTools(Player)
	local num = 0
	local Holding = nil
	local Character = Player.Character
	if Character then
		for i,v in pairs(Character:GetChildren()) do
			if v:IsA("Tool") then
				num += 1
				Holding = v
				break
			end
		end
	end
	for i,v in pairs(Player.Backpack:GetChildren()) do
		if v:IsA("Tool") and v ~= Holding then
			num += 1
		end
	end
	return num
end
1 Like

I put the script in a server script

thanks for the reply I will check this out too

Try doing this in a server script

local part = script.Parent
local Players = game:GetService(“Players”)

part.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent) 
    If player then
        local Backpack = player.Backpack:GetChildren()
        If #Backpack ~= 1 then
              — there is more/less than one tool
        end
    end        
end)

Sorry if there are any formatting issues since I am currently on mobile

1 Like

It Works Thanks alot for the help

1 Like