Touched not connecting

i am returning the connection

Connections[TaggedPart][i] = func(TaggedPart) -- here i store the connection in a table


-- this function disconect the conection in case it is no longer a killpart
CollectionService:GetInstanceRemovedSignal(i):Connect(function(TaggedPart)
		Connections[TaggedPart][i]:disconnect()
		Connections[TaggedPart][i]=nil
	end)

tried this and it worked.?

local CollectionService = game:GetService("CollectionService")
local Connections = {}

local Part = Instance.new("Part") 
Part.Parent = game.Workspace 
CollectionService:AddTag(Part,"Kill")

wait(1)

	local func = require(script.Kill)
	local TaggedParts = CollectionService:GetTagged("Kill")
	
	for _, TaggedPart in pairs(TaggedParts) do
		if Connections[TaggedPart] == nil then
			Connections[TaggedPart] = {}
		end
		Connections[TaggedPart] = func(TaggedPart)
	end

	CollectionService:GetInstanceAddedSignal("Kill"):Connect(function(TaggedPart)
		if Connections[TaggedPart] == nil then
			Connections[TaggedPart] = {}
		end
		Connections[TaggedPart] = func(TaggedPart)
	end)
	CollectionService:GetInstanceRemovedSignal("Kill"):Connect(function(TaggedPart)
		Connections[TaggedPart]:disconnect()
		Connections[TaggedPart]=nil
	end)

local Part = Instance.new("Part") 
Part.Parent = game.Workspace 
CollectionService:AddTag(Part,"Kill")

Maybe you’d have a better, much easier time defining whether it can be active or not by using an external value such as an attribute, or just a boolean instead, so you can re-instantiate it instead of calling to a new connection event, which would just overall take up more memory.

i think i found the issue, it’s the name of the tags. you add “kill” while the wanted name is “Kill”?

Not sure but this worked on my end, i even spawned a part manually on CMD

in top of the collectionservice i do

i=v.Name

if this was the case non of the killparts should have worked

can u share me your script so i can compare it?

Wouldn’t a better way of going about this just be by using a value that’s stored in the parts address instead? Simply put, a boolean you can contain several other values so you don’t have to re-define the connection.

I’m not sure how much a .Touched connection takes up in general (regarding memory), but maybe it’d be a more efficient way to just use a boolean externally instead, so you don’t have to ever call to disconnect, or call to re-connect?

Surely that’s more efficient, is it not?

i basically just replicated yours
image

Code i used

local CollectionService = game:GetService("CollectionService")
local Connections = {}

local Part = Instance.new("Part") 
Part.Parent = game.Workspace 
CollectionService:AddTag(Part,"Kill")

wait(1)

	local func = require(script.Kill)
	local TaggedParts = CollectionService:GetTagged("Kill")
	
	for _, TaggedPart in pairs(TaggedParts) do
		if Connections[TaggedPart] == nil then
			Connections[TaggedPart] = {}
		end
		Connections[TaggedPart] = func(TaggedPart)
	end

	CollectionService:GetInstanceAddedSignal("Kill"):Connect(function(TaggedPart)
		if Connections[TaggedPart] == nil then
			Connections[TaggedPart] = {}
		end
		Connections[TaggedPart] = func(TaggedPart)
	end)
	CollectionService:GetInstanceRemovedSignal("Kill"):Connect(function(TaggedPart)
		Connections[TaggedPart]:disconnect()
		Connections[TaggedPart]=nil
	end)

local Part = Instance.new("Part") 
Part.Parent = game.Workspace 
CollectionService:AddTag(Part,"Kill")

what do you ahve in the module script?

image

image

anyways i think its due to your script listening for “GetTagged(“Kill”)”

while you’re adding the tag “kill”

was reffering to this wasn’t capitalized

CollectionService:AddTag(child,"kill")
1 Like

I see what you’re trying to do now. That makes more sense, I should’ve probably read through this entirely. :sweat_smile:

It looks like @EnigmaticDevil figured out the issue for you, here, though.

My bad!!

1 Like

I was so focused on the other parts I completely overlooked this.
thank you both

2 Likes