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

How to make a part keeps on respawning and make players die on touch?

Asked by
micmnm4 18
7 years ago

How to make a part keeps on respawning and make players die on touch?

0
Please explain further on what you mean farrizbb 465 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Okay, so I don't know about the respawning part, as I've zero knowledge about it.

As for killing the players as they touch the part; you have several ways to do this.

The simplest unprofessional way for doing this, is to set the Health of whoever Humanoid touches the part to 0, or decrease it by 100.

You would write something like this:

local function OnTouch(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        hum.Health = 0
    end
end

script.Parent.Touched:connect(OnTouch)

I guess you're a bit new to scripting, so I'd like to try and explain the script for you, as good as I can.

So, you basically assign a new function "OnTouch" which can be named with whatever name pops out in your mind - except for some specific words which define some concepts in Lua.

Then you set the parameter for your function "(hit)", which indicates whatever hits the part.

Now, you assure that the body that touched your killing part is a player, so you check whether he has a Humanoid or not. (P.S. This way is unprofessional, and - under certain circumstances - can get wrong results, because not all bodies that contain a Humanoid are players.)

Now the killing part, you simply call the Humanoid that we previously mentioned, access its property 'Health', and set it to 0.

Finally, you write the last line, which connects the event of killing the player to the event of the him/her touching the part.

Also, be sure to put this script into the killing part.

1
You could use the GetPlayerFromCharacter function from the Player's service to accomplish this (about how to check if the figure is an actual player.) TheeDeathCaster 2368 — 7y
0
Also, to note, you could use BreakJoints function instead of settings the player's help to 0. TheeDeathCaster 2368 — 7y
0
Thanks for advice. kudorey619 138 — 7y
Ad

Answer this question