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

Why doesn't my script print the touching parts?

Asked by
Jexpler 63
5 years ago

Here is my script:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local gett = script.Parent:GetTouchingParts()
    for i,v in pairs(gett) do
        print(v.Name)
    end
end)

It doesn't work.

0
Oh wait. The part had cancollide off. Is there a way to get the touching parts if the part has cancollide off? Jexpler 63 — 5y
0
if it is a block and you didn't rotate it, you can try region3 theking48989987 2147 — 5y
0
if it is a block and you didn't rotate it, you can try region3 theking48989987 2147 — 5y
0
magnitude greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
5 years ago
Edited 5 years ago

If you read the reference page for GetTouchingParts(), you'll see that if the "part itself has CanCollide set to false, then this function will return an empty table unless it has a TouchInterest." In order to insert a to fix your problem, you can temporarily connect a listener to the part's Touched event, call GetTouchingParts(), and then call Disconnect() on the RBXScriptConnection (as highlighted here).

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local connection = script.Parent.Touched:Connect(function() end)
    local gett = script.Parent:GetTouchingParts()
    connection:Disconnect()
    for i,v in pairs(gett) do
        print(v.Name)
    end
end)

If you ever need to permanently connect an event listener to the Touched event, remove this fix because it will interfere with the actual event listener.

Ad

Answer this question