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

How do I Touch Detect?

Asked by 10 years ago

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

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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)
0
As I said to the guy above, thanks so much for helping! DiscoStriker 20 — 10y
Ad
Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

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)
0
Thank you! This is actually REALLY helpful! DiscoStriker 20 — 10y

Answer this question