Advertisement
Guest User

Roblox Health Script

a guest
Nov 11th, 2018
4,957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. health script
  2.  
  3. 1 --Responsible for regening a player's humanoid's health
  4. 2
  5. 3 -- declarations
  6. 4 local Figure = script.Parent
  7. 5 local Head = Figure:WaitForChild("Head")
  8. 6 local Humanoid = Figure:WaitForChild("Humanoid")
  9. 7 local regening = false
  10. 8
  11. 9 -- regeneration
  12. 10 function regenHealth()
  13. 11 if regening then return end
  14. 12 regening = true
  15. 13
  16. 14 while Humanoid.Health < Humanoid.MaxHealth do
  17. 15 local s = wait(1)
  18. 16 local health = Humanoid.Health
  19. 17 if health > 0 and health < Humanoid.MaxHealth then
  20. 18 local newHealthDelta = 0.01 * s * Humanoid.MaxHealth
  21. 19 health = health + newHealthDelta
  22. 20 Humanoid.Health = math.min(health,Humanoid.MaxHealth)
  23. 21 end
  24. 22 end
  25. 23
  26. 24 if Humanoid.Health > Humanoid.MaxHealth then
  27. 25 Humanoid.Health = Humanoid.MaxHealth
  28. 26 end
  29. 27
  30. 28 regening = false
  31. 29 end
  32. 30
  33. 31 Humanoid.HealthChanged:connect(regenHealth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement