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

How would I use :GetTouchingParts() and check the names of the parts it returns?

Asked by
nanaluk01 247 Moderation Voter
7 years ago
Edited 7 years ago

How would I use :GetTouchingParts() and check the names of the parts it returns?

I have tried multiple things in ROBLOX Studio with :GetTouchingParts() , but I can't get it to work properly, and yes, my parts are all CanCollide-able.

The ROBLOX Wiki does not explain this that well, so I have yet to understand how I would use it.

Please note: I am not asking for anyone to create a script for me, all I want to know is how I would use :GetTouchingParts() and check the names of the parts it returns.

Any help is greatly appreciated!

1 answer

Log in to vote
6
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

GetTouchingParts() returns a table of parts which are touching the part in question. The description from the wiki is as follows, "Returns a table of all CanCollide true parts that intersect with this part. If the part itself is CanCollide false, then this function will return an empty table. Parts that are adjacent but not intersecting are not considered touching."

Here's an example of how you would apply it; assume this is a Script inside of a Part:

local part = script.Parent;
part.Touched:connect(function() --// When the part is touched, call this function
    local touching = part:GetTouchingParts(); --// Get the table of touching parts.
    for _, p in next, touching do
        print(p.Name..' is touching '..part.Name..'!');
    end;
    print();
end;

This script would print the names of the touching parts as returned by part:GetTouchingParts(). Hope this helped.

Read more: For Loops & Anonymous Functions.

0
Thanks! nanaluk01 247 — 7y
0
No problem. Pyrondon 2089 — 7y
0
you made spaces before the beginn of a line, try pressing TUB at the beginnig of a line SuperAstroGame -2 — 4y
Ad

Answer this question