Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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?

0
Please do more research instead of asking. This is site is ment for asking questions or answering questing despite the name. JesseSong 3916 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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)
Ad

Answer this question