Player only kill part

Is it possible to make a brick that only kills players and no npcs?
Any help is appreciated.

Part.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		if game.Players:FindFirstChild(Hit.Parent.Name) then
			--real player
		end
	end
end)

Check if it exists in the player service.

2 Likes

This works or just:

Part.Touched:Connect(function(HitPart)
if game.Players:FindFirstChild(HitPart.Parent.Name) then
--kill
end
end)
1 Like

when getting the humanoid, also check for the player via game.Players:GetPlayerFromCharacter(Humanoid.Parent), if that returns true proceed in killing
in code;

Part.Touched:Connect(function(Part)
 if Part.Parent:FindFirstChild("Humanoid") then
  if game.Players:GetPlayerFromCharacter(Part.Parent) then
   Part.Parent.Humanoid.Health = 0
  end
 end
end
1 Like

It is possible! Using the :GetPlayerFromCharacter function, you can make the Brick only kill players and not NPC’s! I’ll show a small example:

function Touched(Hit)
   local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
   if Player then
       Player.Character.Humanoid.Health = 0
       print(Player.Name.." has hit this kill brick!")
    end
end

script.Parent.Touched:Connect(Touched)
4 Likes