Is this function considered 'hacky'

In Railway Experiences, a small train control system, I have written a small function for tricking roblox into creating a touch interest, since I need to use GetTouchingParts() in the code and the part is CanCollide false

My question is if this function is ‘hacky’

function RETS.InitialiseAllSpawners()
    for _, v in pairs(workspace.SpawnRegions:GetDescendants()) do
        if v.Name == "OccupancyDetector" and not v:FindFirstChild("TouchInterest") then
            v.Touched:Connect(function() end) -- tricks roblox into making a TouchInterest, might be a bit hacky tho
        end
    end
end```
1 Like

I mean yes, you can do this, but this is not ideal (unless you use a table or something to store these connections so you can disconnect them when needed). Leaving connections like that can cause unwanted memory leaks.

Yes, this is a hacky function.

Edit: since you do not reference the part instance indirectly, there will be no issues with garbage collection, and thus, no memory leak.

1 Like

TouchInterests making GetToucingParts work with parts that have CanCollide false is documented, so it isn’t hacky.

This is a non issue. The function specifically checks if there is already a touched interest, so it only creates a connection once. The connections also get disconnected when the parts get destroyed, so there will never be a memory leak. That thread you linked is specifically about where the function references the part it’s connected to, which the blank function doesn’t.