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

Can onTouch functions detect NPC humanoids?

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

1 comment

0

Yes, just make sure it's 'Humanoid' within the NPC if it's not, then add it into the script.

1 answer

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.

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