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

Is there a way make a part which is able to take damage like a NPC?

Is there a way make a part which is able to take damage like a NPC? Can anyone send me a link or how to do it?

1 comment

0

Please do more research instead of asking. This is site is ment for asking questions or answering questing despite the name.

1 answer

✓ Accepted answer

BaseParts have a RBXScriptSignal called Touched which fires when the part is touched. You can use this to detect when the part is touched and then if the script can find a humanoid in the part's parent, damage that humanoid. Here's an example (this will also damage players).

-- If you are going to use this code, make sure to put it in a SERVER script under the part
local Part = script.Parent

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then -- If the parent of the part touched has a humanoid then
		hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(10) -- Take 10 damage
	end
end)

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