Constantly Remove all TouchInterest

The game I’m working on relies a lot on tools. Unfortunately, Roblox insists that every tool should have a touch interest. Every time I drop a tool, a touch interest is generated in the tool, so deleting them manually doesn’t do much.

local descendants = game.Workspace:GetDescendants()


while true do
	wait(1)
for _, descendant in pairs(descendants) do
	if descendant:IsA("TouchInterest") then
			descendant:Destroy()
		end
	end
end

I made this quick script to try to deal with it, but it doesn’t seem to work, and I’m not sure why.

1 Like

I personally don’t recommend using this method to clean up TouchInterests as it seems quite performance-heavy. I would recommend looking into DescendantAdded

However if you insist on using this approach, the reason your code isn’t working in because you’re not redefining descendants on every loop. (Therefore, new descendants of workspace will not be iterated through).

You can solve this by doing the following:

while wait(1) do
	local descendants = game.Workspace:GetDescendants()
	for _, descendant in pairs(descendants) do
		if descendant:IsA("TouchInterest") then
			descendant:Destroy()
		end
	end
end
1 Like

It’s generating the GetDescendants table at the beginning of the script. You need to get the descendants during each new loop in the while true do loop.

This isn’t really a good way to do this, however. TouchInterests are generated for any BasePart with a Touched listener connected, and deleting them effectively neuters all Touched listeners. It’s also running in a while loop, when it really makes more sense as a listener. In addition, I’m pretty sure tools are dropped as direct children of workspace, so you may not even need to get all descendants.

I suggest you do something like this:

workspace.ChildAdded:Connect(function(item)
    if item:IsA("BackpackItem") then
        for _, touchInterest in item:GetDescendants() do
            if touchInterest:IsA("TouchInterest") then
                touchInterest:Destroy()
            end
        end
    end
end)
1 Like

I just found out disabling the CanTouch property in the handle removes the TouchInterest functionality. Thanks for your suggestions

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.