Basically I need a brick that kills you when touched. Tell what the code is like for example "if (touch) bla bla bla"
How do I make a brick that kills you?
2 answers
You shall utilize the BasePart.Touched event.
part.Touched:Connect(function(touchingPart)
if touchingPart.Parent:FindFirstChild("Humanoid") then
touchingPart.Parent.Humanoid.Health = 0
end
end)
4 comments
You should explain more seeing as this person obviously has little to no knowledge of coding or lua. This answer could be considered spoon-feeding.
Then post a better answer, 0-repper.
If you're gonna talk like that, I will.
Scratch that, I'm not going to answer a non-constructive question like this one.
You'll use the following script:
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0
end
end)
But that's quite confusing, let's break it down.
part.Touched:Connect(function(hit)
In this section, we tell the part to connect to a function using "hit" as an argument. If you wonder what "hit" is, try doing:
part.Touched:Connect(function(hit)
print(hit)
end)
It should print a body part of the humanoid, and every body part is parented to the player's character.
if hit.Parent:FindFirstChild("Humanoid") then
This line of code will check if the Humanoid actually exists, preventing errors if something like a tool or a flying part touches the other part.
hit.Parent.Humanoid.Health = 0
This is the last thing the script will do before ending, it's going to get the body part parent (Character) and refer to the humanoid's property "Health". After that, the script is going to set the health to 0.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You need to attempt the problem first.