Heres the script:
01 | local Teleport = "Tele4" |
02 |
03 | function Touch(hit) |
04 | if script.Parent.Locked = = false and script.Parent.Parent:findFirstChild(Teleport).Locked = = false then |
05 | script.Parent.Locked = true |
06 | script.Parent.Parent:findFirstChild(Teleport).Locked = true |
07 |
08 | local Pos = script.Parent.Parent:findFirstChild(Teleport) |
09 | hit.Parent:moveTo(Pos.Position) wait( 1 ) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false |
10 |
11 | end |
12 | end |
13 |
14 | script.Parent.Touched:connect(Touch) |
What I'm trying to do is make it if the players health is 0 (dead) then this script will not teleport them anywhere. Can someone help me with this?
Since Touched event provides you with the object that touched it, you can check if the parent of that part contains a Humanoid. You should always perform this check when you only want players to touch something. From there you can check the Health property of the humanoid is greater than 0.
01 | script.Parent.Touched:Connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
03 |
04 | --We got a player that touched |
05 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
06 |
07 | if humanoid.Health > 0 then |
08 | --Rest of your code goes here |
09 | else |
10 | --If the player is dead then don't do anything |
11 | return |
12 | end |
13 | end |
14 | end ) |