How to make a part keeps on respawning and make players die on touch?
How to make a part keeps on respawning and make players die on touch?
1 answer
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.
3 comments
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.)
Also, to note, you could use BreakJoints function instead of settings the player's help to 0.
Thanks for advice.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Please explain further on what you mean