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

Can onTouch functions detect NPC humanoids?

Asked by 9 years ago

I want to create a "pressure plate" system that can be activated by NPCs. All I need to know is if it is possible.

0
Yes, just make sure it's 'Humanoid' within the NPC if it's not, then add it into the script. lomo0987 250 — 9y

1 answer

Log in to vote
0
Answered by
emite1000 335 Moderation Voter
9 years ago

Yes. In script after onTouch just have it check to see if the part that touched it has a Humanoid in it (or some other thing that all your NPC's have in them).

Probably the easiest way to check if the part has a Humanoid in it is to use the FindFirstChild method. For example:

function onTouch (part.)
IsHuman = part.Parent:FindFirstChild(Humanoid) -- Checks if there is a child called "Humanoid" in the part that touched.
    if IsHuman then print("A human is touching the pad!") -- If it is true and there IS a Humanaoid then print this.
    else print("This is not a human touching the pad!") -- If it is false and there ISN'T a Humanoid, then print this.

Workspace.pad.Touched:connect (onTouch)

However, be careful if you do check for Humanoids for the pressure pads, because Players have Humanoids in them too so that script would be true if a Player was touching it. If you want the script to check for something else besides a Humanoid, just change out the word "Humanoid" at line 2 for something else.

Just as a side note this is how people make Kill scripts that kill only players. They check for a Humanoid, and then if it is found they set the Humanoid's health to 0.

Ad

Answer this question