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

How to make a kill block to kill player?

Asked by
qurt_t 7
4 years ago

I'm really new in scripting.

I started my first game and it have a kill block, when player touch it, it should kill the player.

My code:

local trapPart = script.Parent

local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        -- Set player's health to 0
        humanoid.Health = 0
    end
end
trapPart.Touched:Connect(onPartTouch)

I have no idea why this doesn't work, can you help me?

2 answers

Log in to vote
1
Answered by
c0nc3rt 61
4 years ago

Lol, that script is outdated.

You should use this instead:

script.Parent.Touched:Connect(funtion(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent:BreakJoint()
    end
end)

Anddd.. Boom, you are done. :)

0
^ AswormeDorijan111 531 — 4y
Ad
Log in to vote
2
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

I think your script it's outdated so it didn't work for you.

Scripts that kill players were easy to do. So, let figure out how it works.

script.Parent.Touched:Connect(function(hit)

end)

Function 'hit' is a neutral function, so if the script's parent touched this will connect function 'hit'.

'end)' is a thing that automatically adds while your connect's bracket has a function.

script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then

    end
end)

Line 2 means if 'hit' and the parent (People) who touched and find a thing named 'Humanoid'.

'end' is used for ends the if...then statement.

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

Line 3 shows the people who touched will get the humanoid and make the health become 0.

I hope I helped, and thanks for reading patiently! I hope you have a nice day :D, bye!

0
^ c0nc3rt 61 — 4y
0
? Xapelize 2658 — 4y
0
Upvote boi c0nc3rt 61 — 4y
0
What Xapelize 2658 — 4y
0
I already upvoted ur question reeeEEeeE Xapelize 2658 — 4y

Answer this question