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.
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.