You can use CollectionService and add tags into Parts. For example, If it’s an Obby (Or something that kills the Players) you can create a “Killer” tag. If you want to know how to create tags and manage them, I recommend you to use TagEditor.
And if you ask, Why is it better to use CollectionService?
Well, CollectionService is a great alternative to organize all your Objects in sections and keep stuff organized. So you don’t need to loop through alot of Objects and do alot of checks. (Name, Properties, etc)
The code for this would look like this:
local CollectionService = game:GetService("CollectionService")
local KillerPartTag = "Killer"
local KillerParts = CollectionService:GetTagged(KillerPartTag)
for KillerIndex, KillerObject in pairs(KillerParts) do
if KillerIndex and KillerObject then
-- We have a KillerObject
-- Now we can do something with it.
-- Here's how you would do the kill system:
local TouchedConnection = nil
local AncestryConnection = nil
-- Touched Connection
-- This is gonna hold the Touched Connection
-- Whenever something touches the Object.
TouchedConnection = KillerObject.Touched:Connect(function(Hit)
if Hit and Hit.Parent then
-- If something has hit the Object and it has a parent
-- We're gonna run this
local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and Humanoid.Health > 0 then
-- We have a Humanoid and it's alive!
-- Meaning that we can modify it/kill!
Humanoid.Health = 0
-- Ancestry Connection
-- This is gonna hold the Connection whenever
-- The Object Ancestrys' (Parent) Changes
AncestryConnection = KillerObject.AncestryChanged:Connect(function(Child, Parent)
if not Parent then
-- The part was destroyed
-- We have to Clean-up the connections!
TouchedConnection = nil
AncestryConnection = nil