I need help doing this. I am gonna make an obby.
You can use the Touched event with a part like so:
1 | part.Touched:connect( function (hit) |
And then you can find out if the part belongs to a player like this:
1 | humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
2 | if humanoid ~ = nil then |
And then you can use your favorite method for killing a player, here is mine:
1 | hit.Parent.Torso:Destroy() |
And then all together we have this:
1 | part.Tocuehd:connect( function (hit) --Touched event! |
2 | humanoid = hit.Parent:FindFirstChild( "Humanoid" ) --Finding the Humanoid! |
3 | if humanoid ~ = nil then --If the humanoid exists! |
4 | hit.Parent.Torso:Destroy() --Killing the player! |
5 | end |
6 | end ) |
Use a script that upon touch humanoid health = 0
In obbies, people like chances, so make it upon touch damage humanoid 30 to 40
You can use this script:
1 | function Touched(hit) |
2 | humanoid-hit.Parent.findFirstChild( "Humanoid" ) |
3 | if Humanoid ~ = nil then |
4 | Instance.new( "Part, Head" ) |
5 | hit.Head:Destroy() |
6 | end |
7 | end |
8 |
9 | script.Parent.onTouched:connect(hit) |
Hello Allisaurus!
This simple script will kill a player on touch.
The green text explains what each part does.
01 | bin = script.Parent --This is a variable. We can use this later, in the function. |
02 |
03 | function onTouched(Part 2 ) --This is the function. |
04 | local h = Part 2. Parent:FindFirstChild( "Humanoid" ) --We are searching for the player's body here. |
05 | if h then --If it is there, then.... |
06 | while h.Health > 0 do --Check if it's health is greater than zero. I'm not sure if this is needed, but I keep it anyway. |
07 | h.Health = h.Health - 100 --Take away the player's health. |
08 | wait( 1 ) --Waits a second. Probably not needed either, but whatever. |
09 | end |
10 | end |
11 | end --Ends the function. |
12 |
13 | bin.Touched:connect(onTouched) --This connects the function. |
I hope this helps. Good luck with your obby!
script i use is 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)
It's easy, you would just need a upontouched(), and a function to take the players health down to zero. On free models, there are loads of scripts that do exactly that.