You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
when you touched a part you die
What is the issue? Include screenshots / videos if possible!
for the parts already in the game. this works, however, parts later added into the game doesn’t get a TouchInterest
the print in the kill script does fire with the right part
but it seems like the connect does nothing
my scripts
Image of explorer
Collectionservice
local CollectionService = game:GetService("CollectionService")
local Connections = {}
for i,v in pairs(script:GetChildren()) do
i=v.Name
local func = require(v)
local TaggedParts = CollectionService:GetTagged(i)
for _, TaggedPart in pairs(TaggedParts) do
if Connections[TaggedParts] == nil then
Connections[TaggedParts] = {}
end
Connections[TaggedParts][i] = func(TaggedPart)
end
CollectionService:GetInstanceAddedSignal(i):Connect(function(TaggedPart)
if Connections[TaggedPart] == nil then
Connections[TaggedPart] = {}
end
Connections[TaggedPart][i] = func(TaggedPart)
end)
CollectionService:GetInstanceRemovedSignal(i):Connect(function(TaggedPart)
Connections[TaggedPart][i]:disconnect()
Connections[TaggedPart][i]=nil
end)
end
KillScript
return function (TaggedPart)
if TaggedPart:IsA("BasePart") then
print(TaggedPart)
local debounce = true
local con = TaggedPart.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and debounce then
debounce = false
Humanoid:TakeDamage(100)
wait(1)
debounce = true
end
end)
return con
else return nil
end
end
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
return function (TaggedPart)
if TaggedPart:IsA("BasePart") then
print(TaggedPart)
local debounce = true
local con = TaggedPart.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and debounce then
debounce = false
Humanoid:TakeDamage(100)
wait(1)
debounce = true
end
end)
con.Parent = TaggedPart -- this is the new line!!!
return con
else return nil
end
end
“parts later added into the game doesn’t get a TouchInterest” where is this? do you spawn em using a script?, anyways simply you have to add connections to the later spawned parts or “Tagging em” with your collection service then adding the Kill Function on it whatever you prefer
>Part Spawns
>Adds Touched Connection on it basically re-executing the kill script on it
i use a script to spawn the items in yes.
from there i put them into a folder
Script that adds part to CollectionService
local CollectionService = game:GetService("CollectionService")
game.Workspace.BTools.DescendantAdded:Connect(function(child)
if child:IsA("BasePart") then
if child.Color == Color3.new(1,0,0) then
CollectionService:AddTag(child,"kill")
end
child:GetAttributeChangedSignal("Color"):Connect(function(newcolor)
if newcolor == Color3.new(1,0,0) then
CollectionService:AddTag(child,"kill")
elseif CollectionService:HasTag(child,"kill") then
CollectionService:RemoveTag(child,"kill")
end
end)
end
end)
I checked if the part gets added to the collectionservice.
(it does)
and if it triggers the CollectionService:GetInstanceAddedSignal
(it does)
in here you can see the script that adds the tags to the parts
the collectionservice script has an event GetInstanceAddedSignal
this event does trigger when a part gets added to the collection server
inside the Killscript I made a print to see on what parts this function runs
the print inside the kill script does get triggered with the right part
this is a signal for me that – the part has been added to collectionservice(kill)
and that the script is trying to turn it into a killpart
haven’t really use CollectionService yet but i do know that it shoud work like Getchildren loops, anyways GetInstanceAddedSignal Should be detecting the later added parts if i assume it works like ChildAdded
If I’m being honest, I know you wrote your entire framework over the fact that, it should be using the .Touched connection, however… there are plenty of better ways to do this:
A.) Region3’s.
B.) Raycast
If you’re looking for super-accurate hitboxes, check out this module somebody made.
the .Touched connection event is very insecure, not 100% reliable, and overall… is just really bad, so I suggest you use one of these alternatives instead. Best of luck!
Even if he does eventually fix it, .Touched is overall just a really bad implementation for hitboxes. It’s super insecure, inaccurate, I could go on really… but, for the sake of time, just use one of these alternatives.
Yeah, honestly, it’s probably not even worth fixing. Again, once he does fix it, he’ll most likely have event issues regarding whether it connects or not in the future, so honestly he should probably just abandon this and hop on a better solution!
But, that’s just my take. I’m not saying he should, but it’s probably a better alternative altogether to just use a better, more efficient method.
So, from what I understand, you’re essentially trying to make a kill brick?
Why not instantiate a region3 for each kill brick, have each kill brick non-can collide, and if anything steps into it at any given time, execute the code you’re trying to, (aka kill them?)
The instance of which has been touched? Or the connection itself? I’ve been reviewing some of your code, and from what I’m seeing, it kind of looks like you’re trying to return the connection event as a whole. I’m not entirely sure if you’re going to get any expected results by returning just the connection event.
Maybe instead, return the character inside the .Touched connection, then that way, when you return the connection, it’ll maybe return that character as well?