How to check if a player does not have an tool?

Hey i’m wondering how to check if a player has a tool i tried this

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
	if player.Backpack.Shotgun == nil then
		local Gun = game.ReplicatedStorage.Shotgun:Clone()
		Gun.Parent = player.Backpack
	end
	end)

but it didn’t work instead i got Shotgun is not a valid member of Backpack “Players.DevFoll.Backpack”

1 Like

i figured it out my new script

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
	local Tool = player.Backpack:FindFirstChild("Shotgun") or player.Character:FindFirstChild("Shotgun")
	if Tool == nil then
		local Gun = game.ReplicatedStorage.Shotgun:Clone()
		Gun.Parent = player.Backpack
	end
	end)
1 Like

To see if they have a tool more efficiently,

for i, v in pairs(Player.Character:GetChildren()) do
	if v:IsA("Tool") then
		print("player has a tool equipped!")
	end
end

for i, v in pairs(Player.Backpack:GetChildren()) do
	if v:IsA("Tool") then
		print("player has a tool in their backpack!")
	end
end

this will check if everyone has a tool i don’t want that. Sorry i read the script wrong, I thought u did game.Workspace:GetChildren

It will check if the Player has a tool, not everyone. It will work if done correctly.

Event.OnServerEvent:Connect(function(Player) 
	for i, v in pairs(Player.Character:GetChildren()) do -- only checks the players character who fired the server event
		if v:IsA("Tool") then
			print("player has a tool equipped!")
		end
	end
	for i, v in pairs(Player.Backpack:GetChildren()) do -- only checks the players backpack who fired the server event
		if v:IsA("Tool") then
			print("player has a tool in their backpack!")
		end
	end
end)