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

How do I Touch Detect?

I have no idea where to start. In one of my maps I want to make a pitfall, and I know what to do to make the part move, but I can't make a touch detector. Is there a specific object I don't know about, or is there a script I have to enter to make it know when a person touches it?

2 answers

Yes, it's called the Touched Event.

Here's an example

script.Parent.Touched:connect(function(hit)
	print("AH! Someone or something touched me!")
end)

If you want to know if it's a ROBLOXian, here you go.

script.Parent.Touched:connect(function(hit)
	if hit.Parent and hit.Parent:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then
		print(hit.Parent.Name.." has touched this brick")
	end
end)

1 comment

0

As I said to the guy above, thanks so much for helping!

This function fires when a particular part you can define is touched:

local part = script.Parent -- Location of part to touch

part.Touched:connect(function()
	-- Rest of script goes here
end)

1 comment

0

Thank you! This is actually REALLY helpful!

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