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

How do I make a block that will kill players?

Asked by 8 years ago

Hello, I'am new to scripting and I want to make this block be able to kill a player when it touches it. Is there a way to do this?

0
I'm not going to do the work for you. You have to learn to script on your own User#9949 0 — 8y
0
Ok thanks TitanSoft 10 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

You can either just find the humanoid or find the humanoid and :GetPlayerFromCharacter() . It all depends on what requirements you want the touched event to have. One basic way in writing this could be :

script.Parent.Touched:connect(function(hit) -- Assuming this script is in the block, server script. The "hit" is the parameter to connect the Touched event.
local hum = hit.Parent:FindFirstChild("Humanoid") -- You don't put hit.Parent.Character because the hit.Parent is the character. You also find the humanoid because you will eventually be taking health off of the player and this is where the health resides.
if hum ~= nil then --Scripters use this so we can check what is touching the brick is actually  a humanoid, this way the script won't error or crash.
hum.Health = hum.Health - 100 --This will instantly kill the player, you can adjust the amount of health you want taken off by changing the "100" to whatever you want. To be on the safe side though you could do "hit.Parent:BreakJoints()". This is a safer way because a person with admin might change their health to lets say "10000000000" and the script would only subtract a 100, resulting in them not dying.
end
end)

If this helped you please don't forget to give a thumbs up and accept the answer. If it errored or you have any questions please comment on my answer and I will be glad to help.

0
you could just put hum.Health = 0 DeveloperSolo 370 — 8y
0
Or you could also use TakeDamage(100) instead which is more prefered... EzraNehemiah_TF2 3552 — 8y
0
I said one of the basic ways lol yougottols1 420 — 8y
0
When spawning, a player character will get a force field so as to not get instantly killed by other players or environmental hazards. `TakeDamage()` will not damage the player if the character has a force field. This can be a problem for obstacle courses, where a player could try to rush through obstacles while he is invincible. Link150 1355 — 8y
View all comments (6 more)
0
Also, a problem arises with `humanoid.Health = humanoid.Health - 100` if the humanoid's MaxHealth property is above 100. The best is to directly set the Health property to 0, in this case. Link150 1355 — 8y
0
@yougottols1 I'm sorry, but I have to downvote your answer. Your answer itself is relatively good, but your comments take more space than the code; it hurts readability. You could easily improve readability by shortening them or moving them outside of your code block. Do this, and I shall reconsider my downvote. Link150 1355 — 8y
0
@Link150 I did say that :BreakJoints() Could work too to be more safer... yougottols1 420 — 8y
0
Harsh User#11440 120 — 8y
0
or you can do on line 4, PhoenixVortex_RBLX 33 — 7y
0
hum.Health = 0 PhoenixVortex_RBLX 33 — 7y
Ad
Log in to vote
0
Answered by 8 years ago

Try this:

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

Answer this question