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 4 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.
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild ("Humanoid")then
           hit.Parent:BreakJoints()
               end
          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 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
function onTouch(part) 
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    if (humanoid ~= nil) then   -- if a humanoid exists, then
        humanoid.Health = 0 -- damage the humanoid
    end 
end

script.Parent.Touched:connect(onTouch)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This should work:

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

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 — 4y
Log in to vote
0
Answered by 4 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:

script.Parent.Touched:Connect(function(hit)
    local Char = hit:FindFirstAncestorOfClass("Model")

    Char.Humanoid.Health = Char.Humanoid.Health - Char.Humanoid.Health
end

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