Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a brick that will instantly kill the player when touched?

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
1script.Parent.Touched:Connect(function(hit)
2    if hit.Parent:FindFirstChild ("Humanoid")then
3           hit.Parent:BreakJoints()
4               end
5          end
0
This is the script for you guys to make a lava jump stage for your obby! put this script in the lava!!! stefcetominecraft1 0 — 5y

3 answers

Log in to vote
1
Answered by 5 years ago
1function onTouch(part)
2    local humanoid = part.Parent:FindFirstChild("Humanoid")
3    if (humanoid ~= nil) then   -- if a humanoid exists, then
4        humanoid.Health = 0 -- damage the humanoid
5    end
6end
7 
8script.Parent.Touched:connect(onTouch)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This should work:

1script.Parent.Touched:connect(function(hit)
2    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
3        hit.Parent.Humanoid.Health = 0
4    end
5end)

Please contact me when this is not what you ment or if it doesn't work.

1
Don't just assume that was it when no info was given. btw hit and hit.Parent will never be nil. programmerHere 371 — 5y
Log in to vote
0
Answered by 5 years ago

Since you only gave info in your title, I can only go off that. But, for what the title is asking, this is what I do:

1script.Parent.Touched:Connect(function(hit)
2    local Char = hit:FindFirstAncestorOfClass("Model")
3 
4    Char.Humanoid.Health = Char.Humanoid.Health - Char.Humanoid.Health
5end

Obviously, this wouldn't work if you put another model in-between the character and hit. But the reason I do this, is because if an accessory touched the part, hit.Parent wouldn't work. So this way, it checks for the first model that hit is in.

Answer this question