Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Does the TakeDamage() function not work on NPC humanoids?

I am using the TakeDamage() function in a tool to damage NPC humanoids. These humanoids only have a head, string value, bool value, and Humanoid object.

When using this function the humanoid does not take damage.

If it is something I am doing wrong then maybe you can help me.

Here is my script.

local Tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local isEquipped = false

function attack(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	print("attack")
	if human then
		print("human")
		human:TakeDamage(10)
	end
end

function swordUp()
	Tool.GripForward = Vector3.new(-1,0,0)
	Tool.GripRight = Vector3.new(0,1,0)
	Tool.GripUp = Vector3.new(0,0,1)
end

function swordOut()
	Tool.GripForward = Vector3.new(0,0,1)
	Tool.GripRight = Vector3.new(0,-1,0)
	Tool.GripUp = Vector3.new(-1,0,0)
end

script.Parent.Equipped:connect(function()
	isEquipped = true
end)

script.Parent.Unequipped:connect(function()
	isEquipped = false
end)

mouse.Button1Down:connect(function()
	if isEquipped == true then
		swordOut()
		wait(0.1)
		swordUp()
	end
end)

script.Parent.Handle.Touched:connect(attack)

Both print statements inside my attack function print.

1 answer

✓ Accepted answer

TakeDamage does work on NPCs.

However, it only works on alive humanoids. A humanoid without a Neck joint connecting their Head and Torso is not considered alive.

The Wiki documents this..

This discussion is preserved as it was. New answers, comments, and votes are closed.