Need help with disconnecting event

Hello ,

I have problem with disconnecting event . Here is what I mean

for i , newchild in pairs(Collection:GetTagged("Mob")) do
      
       --- blah blah
end

from the script above I loop thorugh tagged part called mob . Now the questions is if the newchild is dead , how can I disconnect event only for it.

this is what I currently have

DeadCon = newchild:WaitForChild("Humanoid").Died:Connect(function()
				
				RunServCon:Disconnect()
				ToucedCon:Disconnect()
				
				task.wait(2)
				
				Collection:RemoveTag(newchild , "Mob")
				
				DeadCon:Disconnect()
				
			end)

the problem is rn that its disconnecting all instead dead one . Any clue for this ?? . Any help is appriciated :slight_smile: :slight_smile:

If you need anything feel free to say it to me

1 Like

If this is within the iteration loop, it should only disconnect the one. Could you post the full script related to that area?

here:

		for i , newchild in pairs(Collection:GetTagged("Mob")) do

                       -- some stuff not related here--
			
			DeadCon = newchild:WaitForChild("Humanoid").Died:Connect(function()
				
				RunServCon:Disconnect()
				ToucedCon:Disconnect()
				
				task.wait(2)
				
				Collection:RemoveTag(newchild , "Mob")
				
				DeadCon:Disconnect()
				
			end)
		end

So at least from the code you’ve provided, it looks like DeadCon should disconnect for the given item only. The others may be referencing things outside of the iteration.

Oh my bad didn’t see that ::sweat_smile:. I did disconnect the event for all of it …anyway thanks :slight_smile:

1 Like