What would be the BEST way to make a block kill you when you touch it?

Good morning to all of you, I would like to know what would be the best way to make you touch a block to kill you.

I know I can do it with Touched and debounce but sometimes I think there is a more professional way to do it, maybe using Region3 or other things but I want to achieve a soft touch in the end, I do not know if they understand me but I want to know that. What do you recommend me to use?

Thanks for reading !

4 Likes

What do you mean by a soft touch? Touched is far more efficient than Region3

2 Likes

Do you plan on having more than 1 kill block? If so, your best approach would be using CollectionService to make a single touched event for all of the blocks. As LocksOfDispair said, touched is far more efficient than Region3s or any other form of touch checking.

3 Likes

With a soft touch, I mean that not just touching it at the minimum kills me.

The most efficient way to check is using the BasePart.Touched event. Relying on magnitude or Regoin3 can be problematic any time there is server lag.

By “soft touch”, I believe what you are trying to accomplish is not an instant kill but a gradual loss of health, which can be accomplished aswell through touch events.

Here is an example of a kill script located inside the kill brick.

local brick = script.Parent
brick.Touched:connect(function(hit)--hit will be the part that touches the brick
    local h = hit.Parent:FindFirstChildOfClass("Humanoid")--see's if the parent of hit contains a humanoid
    if h then
        h.Health = h.Health - 10 -- the amount of health you want to subtract each time the touch event is fired
    end
end)
6 Likes

If I know how to do that, anyway thanks for your support, I’ll have to use CollectionSevice because I do not just want it for a block

I don’t know why you are using CollectionService for a kill brick? That service is for tagging objects for information and behaviors of objects. This is only to give information to scripts, not to the player. Can you explain in further detail what you are trying to accomplish?

Edit: If you are trying to add the kill function into multiple bricks but a single script, you can use a for loop to create a separate event for each part.

Here is some code to represent how this can be accomplished:

local KillParts = game.Workspace.KillBricks:GetChildren()

for _,KillPart in pairs(KillParts) do
    KillPart.Touched:connect(function(hit)
        local h = hit.Parent:FindFirstChildOfClass("Humanoid")--see's if the parent of hit contains a humanoid
        if h then
            h.Health = h.Health - 10 -- the amount of health you want to subtract each time the touch event is fired
        end
    end)
end
2 Likes

If I understand, as Thundermaker300 told me, I will use CollectionService to create a single hit event for all the blocks (Kill Bricks). You tell me that I can use: GetChildren (), I know but not all the kill bricks will be grouped in a single “Model” they will be in different Models for which I can not use: GetChildren ()

You can create a list of models and get the descendants/children of those models to be added to the table. If you were to use CollectionService, however that may be, you would still end up needing to define each part somehow to actually assign them a tag.

table.insert(KillParts,#KillParts+1,Part2)

uhmm, would it be wrong for me to do it with CollectionService? I’m using “Tag Editor” (Plugin) to create the tags

Something like that would work, I suppose.

local CollectionService = game:GetService(“CollectionService”)

for i, brick in pairs(CollectionService:GetTags(“KillBrick”))do

brick.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		print("Touched")
	end
end)

end

Using collection service is probably better than :GetChildren() if your objects are spit between models or you have more than just the block you want to connect to the function under that model. So in this case you would definitely want to go with CollectionService.

1 Like

Something like that would work, I suppose.

local CollectionService = game:GetService("CollectionService")

for i, brick in pairs(CollectionService:GetTags(“KillBrick”))do


brick.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		print("Touched")
	end
end)
end```

Since you are using a plugin to create tags and not creating them with the script, your way is simpler and more organized. If you were using the script to create tags for each part that would be a different story.

1 Like

Almost. In your loop you would want to call CollectionService:GetTagged(str) because that returns all of the objects that have the tag. GetTags(obj) tells you the tags on a part.

So like this

local CollectionService = game:GetService("CollectionService")

for i, brick in pairs(CollectionService:GetTagged(“KillBrick”))do


brick.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		print("Touched")
	end
end)
end
9 Likes

oh, well I understand, then it’s good what I’m doing … thank you for your time and great support

Touch bricks have a “sensitivity” issue, something to note for the future. A post was made earlier regarding a similar topic and I had a response on how one could modify their kill bricks to be effective.

That being said, this is just an add-on, so have a look in your free time if you want. For the purpose of solving the specific thread’s issue (making a touch-kill block), the suggested solution is wonderful for creating streamlined block behaviour.

1 Like