Advertisement
Rrrrry123

Custom Overhead Health Bar Scripts

Feb 22nd, 2019
2,913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. -- Health Bar Script --
  2. local human = script.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid")
  3.  
  4. -- Change this to false if you want the health bar to be visible even when the player's health is full.
  5. -- If you leave it true, the health bar will disappear when the health is full.
  6. local hideBarAtFull = true
  7.  
  8. human.HealthChanged:Connect(function(newHealth)
  9.     local maxhp = human.MaxHealth
  10.     if maxhp then
  11.         if newHealth == maxhp then
  12.             if hideBarAtFull then script.Parent.Visible = false end
  13.             script.Parent.Frame.Size = UDim2.new(1,0,1,0)
  14.            
  15.         elseif newHealth < maxhp and newHealth > 0 then
  16.             script.Parent.Frame:TweenSize(UDim2.new(newHealth/maxhp,0,1,0), "Out", "Quad", .25)
  17.             script.Parent.Visible = true
  18.        
  19.         else
  20.             script.Parent.Frame.Size = UDim2.new(0,0,1,0)
  21.             script.Parent.Visible = true
  22.         end
  23.     end
  24. end)
  25.  
  26. -- Script in StarterCharacterScripts --
  27. -- Change this line to true if you want the player to be able to see their own health bar.
  28. local showOverLocalPlayer = false
  29.  
  30. -- Changes the seed.
  31. math.randomseed(tick())
  32.  
  33. local colors = script.Colors:GetChildren()
  34.  
  35. local color = colors[math.random(1,#colors)]
  36.  
  37. local char = script.Parent
  38.  
  39. local player = game:GetService("Players"):GetPlayerFromCharacter(char)
  40.  
  41. local gui = script.Display
  42.  
  43. -- Moves the GUI to the player's head, makes it so the player can't see it,
  44. -- and sets it up.
  45. gui.Parent = char.Head
  46.  
  47. if not showOverLocalPlayer then gui.PlayerToHideFrom = player end
  48.  
  49. gui.Frame.Script.Disabled = false
  50. gui.PlayerName.Text = script.Parent.Name
  51. gui.PlayerName.TextColor3 = color.Value
  52.  
  53. -- Hide old player name.
  54. char.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
  55. script:Remove()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement