How to detect if player is holding a tool

I am making an obby and I have a part that is under and over each obby floor so that when the player falls they die but I want to know if I can detect if a player is holding a tool like a magic carpet so that when they fly around they dont die from that part

this is my kill brick code

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")

local Player = Players.LocalPlayer

local Debounce = false

for i, v in CollectionService:GetTagged("KillPlayer") do
	
	if v:IsA("BasePart") then
		
		v.Touched:Connect(function(hit)
			
			if Debounce == false then
				
				Debounce = true
				
				if hit.Parent == Player.Character and Player.Character.Humanoid.Health > 0 then
					
					Player.Character.Humanoid.Health = nil
					
				end
				
				Debounce = false
				
			end
		end)
	end
end

can someone help me and if you do you get solution

When someone has a tool equipped it means the tool is inside their character model. So when they touch the brick, you can just check whether they have the tool in their character or not:

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")

local Player = Players.LocalPlayer

local Debounce = false

for i, v in CollectionService:GetTagged("KillPlayer") do
	
	if v:IsA("BasePart") then
		
		v.Touched:Connect(function(hit)
			
			if Debounce == false then
				
				Debounce = true
				
				if hit.Parent == Player.Character and Player.Character.Humanoid.Health > 0 and not Player.Character:FindFirstChild("MagicCarpet") then
					
					Player.Character.Humanoid.Health = nil
					
				end
				
				Debounce = false
				
			end
		end)
	end
end

you might want to replace MagicCarpet with the actual name of the tool

1 Like

You could check if the player is holding a tool and if it is, then check if the tool has the correct name. Something like this

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")

local Player = Players.LocalPlayer

local Debounce = false

for i, v in CollectionService:GetTagged("KillPlayer") do
	
	if v:IsA("BasePart") then
		
		v.Touched:Connect(function(hit)
			
			if Debounce == false then
				
				Debounce = true
				
				if hit.Parent == Player.Character and Player.Character.Humanoid.Health > 0 then

                   if hit.Parent:FindFirstChildOfClass("Tool") then --checking for a tool
                       print("There is a tool equipped")
                        if hit.Parent:FindFirstChild("TOOLNAME HERE") then --checking for correct tool
					
					    Player.Character.Humanoid.Health = nil
                       end
					end
				end
				
				Debounce = false
				
			end
		end)
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.