Advertisement
Pluem1273

Fall Damage Script

May 10th, 2022
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local min = 10
  2. local max = 30
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     player.CharacterAdded:Connect(function(character)
  6.         local humanoid = character:WaitForChild("Humanoid")
  7.         local rootpart = character:WaitForChild("HumanoidRootPart")
  8.        
  9.         local playerHeight
  10.        
  11.         if humanoid and rootpart then          
  12.             humanoid.FreeFalling:Connect(function(newState)
  13.                 if newState then
  14.                     playerHeight = rootpart.Position.Y
  15.                 elseif not newState then
  16.                     local fallHeight = playerHeight - rootpart.Position.Y
  17.                    
  18.                     if fallHeight >= max then
  19.                         humanoid.Health = 0
  20.                     elseif fallHeight >= min then
  21.                         humanoid:TakeDamage(math.floor(fallHeight))
  22.                     end
  23.                 end
  24.             end)
  25.         end
  26.     end)
  27. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement