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

Humanoid's health won't TakeDamage on Touch?

I created a Tool with only a brick and a script in it. I created a humanoid with only a part named Head in it. When the Tool touches the Humanoid part, the humanoid should lose 10 health. But nothing happens.

The script:

script.Parent.Handle.Touched:connect(function(part)
	part.Parent:FindFirstChild("Humanoid")
	if found then
		Humanoid:TakeDamage(10)
	end
end)

What's wrong?

1 answer

I'm not sure what you mean by if found then, because that wouldn't work. Also you didn't define Humanoid. You could simply do it like this:

script.Parent.Handle.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		hum:TakeDamage(10)
	end
end)

2 comments

0

I thought that the hit event only applied to Explosions? Why are you using it here?

0

hit is just the function name.

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