SHARE
TWEET

Untitled

a guest Jan 24th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local runService = game:GetService("RunService")
  2. local startHeightFallDamage = 10
  3. local damagePerHeight = 1
  4. local humanoid = nil
  5. local character = nil
  6. local lastStepAir = false
  7. local totalAirVecrticalDistance = 0
  8. local lastGroundedPosition = Vector3.new(0,0,0)
  9.  
  10. local function reset()
  11.     humanoid = nil
  12.     character = nil
  13.     totalAirVecrticalDistance=0
  14.     lastGroundedPosition = Vector3.new(0,0,0)
  15. end
  16. runService.Heartbeat:Connect(function()
  17.         if humanoid == nil or character == nil then
  18.             print("waiting for character")
  19.             return
  20.         end
  21.         if humanoid.FloorMaterial == Enum.Material.Air then
  22.             totalAirVecrticalDistance = lastGroundedPosition.Y - character:FindFirstChild("HumanoidRootPart").Position.Y
  23.             lastStepAir = true
  24.             print("Air distance is: "..tostring(totalAirVecrticalDistance))
  25.         else
  26.             if lastStepAir and totalAirVecrticalDistance>startHeightFallDamage then
  27.                 local fallDamage = (totalAirVecrticalDistance-startHeightFallDamage)*damagePerHeight
  28.                 if fallDamage<1 then fallDamage = 1
  29.                    
  30.                 end
  31.                 print("Total fallen distance: "..tostring(totalAirVecrticalDistance))
  32.                 humanoid:TakeDamage(fallDamage)
  33.             end
  34.             lastGroundedPosition = character:FindFirstChild("HumanoidRootPart").Position
  35.             lastStepAir = false
  36.             totalAirVecrticalDistance = 0
  37.         end
  38.        
  39.     end)
  40.  
  41. local function fallDamage(char)
  42.     character =char
  43.     humanoid = char.Humanoid
  44. end
  45. local function onPlayerAdd(player)
  46.     player.CharacterAdded:Connect(fallDamage)
  47.     player.CharacterRemoving:Connect(reset)
  48. end
  49. game.Players.PlayerAdded:Connect(onPlayerAdd)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top