Maximum event re-entrancy depth exceeded

im making a gunshot echo and im using descendant added, but i keep getting this error:

this is my code:

workspace.DescendantAdded:Connect(function(desc)
	if desc:IsA('Sound') then
		if desc.Parent:IsA('BasePart') then
			if (desc.Parent.Position - Root.CFrame.Position).Magnitude >= 30 then
				desc.Volume = 0
				local fx = script.Echo:Clone()
				fx.Parent = desc.Parent
				fx:Play()
				fx.Ended:Connect(function()
					fx:Destroy()
				end)
			end
		end
	end
end)

any ideas?

Well you are adding a child every time a child gets added. Essentially you made an infinite loop. Whenever you parent the clone it fires the event again. If you want an infinite loop you should use a while loop. If you don’t want an infinite loop then you should rework the logic of the system.

Also I’ve never really used these, but this might be worth looking into EchoSoundEffect since it seems to me to do what you’re trying to code.

i changed the sound id instead:

workspace.DescendantAdded:Connect(function(desc)
	if desc:IsA('Sound') then
		if desc.Parent:IsA('BasePart') then
			if (desc.Parent.Position - Root.CFrame.Position).Magnitude >= 30 then
				desc.SoundId = script.Sound.SoundId
			end
		end
	end
end)

but that still makes an error

anyone know a solution yet? this is quite annoying

wait nevermind im overwhelmingly stupid, i wasn’t checking the name of the sound to see if its actually the fire sound effect