Advertisement
dubleeyrblxx

Fall Damage -- Roblox

Jul 5th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. -- Put in ServerScriptService
  2.  
  3. local damageHeight = 14 -- The height at which the player will start getting damaged at
  4. local lethalHeight = 26 -- The height at which the player will get killed
  5.  
  6. game:GetService("Players").PlayerAdded:Connect(function (plr)
  7.     plr.CharacterAdded:Connect(function (char)
  8.        
  9.         local root = char:WaitForChild("HumanoidRootPart")
  10.         local humanoid = char:WaitForChild("Humanoid")
  11.        
  12.         if humanoid and root then
  13.            
  14.             local headHeight
  15.            
  16.             wait(3) -- Prevent the player from dying on spawn
  17.             humanoid.FreeFalling:Connect(function (state)
  18.                 if state then
  19.                     headHeight = root.Position.Y
  20.                 elseif not state and headHeight ~= nil then
  21.                     pcall(function ()
  22.                        
  23.                         local fell = headHeight - root.Position.Y
  24.                        
  25.                         if fell >= lethalHeight then
  26.                             humanoid.Health = 0
  27.                         elseif fell >= damageHeight then
  28.                             humanoid.Health = humanoid.Health - math.floor(fell)
  29.                         end
  30.                     end)
  31.                 end
  32.             end)
  33.         end
  34.     end)
  35. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement