Parts arent being touched

im making this echolocation script, and for some reason when the sphere touches an object it wont glow as intended

heres the inportant part of the code

				soundWave.Touched:Connect(function(hit)
					if not table.find(touchTable, hit) then
						table.insert(touchTable, hit)
						------------
						if hit ~= game.Workspace.Baseplate then
							local hitColor = hit.Color
							local hitTransparency = hit.Transparency
							local hitMaterial = hit.Material
							
							local echoTween = Services.TS:Create(hit, TweenInfo.new(1), {Color = Color3.new(0.917647, 0.698039, 0.25098), Transparency = 0.5})
							echoTween:Play()
							hit.Material = Enum.Material.Neon
							print(hitColor,hitMaterial,hitTransparency)

							task.wait(5)
							print(hitColor,hitMaterial,hitTransparency)
							local endTween = Services.TS:Create(hit, TweenInfo.new(1), {Color = hitColor, Transparency = hitTransparency})
							endTween:Play()
							hit.Material = hitMaterial
						end
						task.wait(5)
						local index = table.find(touchTable,hit)
						if index then
							table.remove(touchTable, index)
						end
					end
				end)

im not sure whats causing the issue but if i had to assume it’d be the table.

help and feedback is appreciated, thank you for your time :grinning:

The issue from what I’m seeing is that the 2nd time you did it the function didn’t work. This would be caused by you not resetting the table with the list of parts it’s already hit

so instead of attempting to remove the hit objects, after 5 seconds just remove every item in the table or state touchTable = {}

1 Like

so something like this?

task.wait(5)
touchTable = {}
1 Like

yes, this should fix your problem. I’d recommend putting it after the sphere disappears so that it’s all cleared at once and there’s no overlapping if you use echolocation rapidly

1 Like