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

How to figure out what the name of a part is when touched?

Asked by 8 years ago

How to find out the name of a part when touched by it.

2 answers

Log in to vote
1
Answered by 8 years ago
local PartToBeTouched = game.Workspace.Part --Name this whatever...

PartToBeTouched.Touched:connect(function(TouchingPart)
print(TouchingPart.Name)
end)

You can do it by using the "OnTouched" event on a part which will fire when "PartToBeTouched" is touched, and the argument is the part which touched it.

Ad
Log in to vote
0
Answered by 8 years ago

Usually, parts in workspace have the same name, so the script that the previous person has provided may not necessarily work. Though it is not recommended, you can add a script under the part. (For me personally, it is very unorganized and I heard it contributes to server lag)

local part = script.Parent

part.Touched:connect(function(touchpart)
print(touchpart.Name)
end)

-- This script goes under the part.

But yes, the scripts are basically the same.

Answer this question