Advertisement
HowToRoblox

DamageIndicator

Jul 14th, 2020
13,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local tweenService = game:GetService("TweenService")
  2.  
  3. local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
  4.  
  5. local damageForColours =
  6. {
  7.     [25] = Color3.fromRGB(255, 196, 101),
  8.     [50] = Color3.fromRGB(255, 234, 0),
  9.     [75] = Color3.fromRGB(255, 140, 0),
  10.     [100] = Color3.fromRGB(255, 0, 0),
  11. }
  12.  
  13. game.Players.PlayerAdded:Connect(function(plr)
  14.    
  15.     plr.CharacterAdded:Connect(function(char)
  16.        
  17.         local humanoid = char:WaitForChild("Humanoid")
  18.         local currentHealth = humanoid.Health
  19.        
  20.         humanoid.HealthChanged:Connect(function(health)
  21.            
  22.             if health < currentHealth and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
  23.            
  24.                 local healthLost = math.floor(currentHealth - health)
  25.                
  26.                
  27.                 local damageIndicatorGui = Instance.new("BillboardGui")
  28.                 damageIndicatorGui.AlwaysOnTop = true
  29.                
  30.                 damageIndicatorGui.Size = UDim2.new(1.5, 0, 1.5, 0)
  31.                
  32.                 local offsetX = math.random(-10, 10)/10
  33.                 local offsetY = math.random(-10, 10)/10
  34.                 local offsetZ = math.random(-10, 10)/10
  35.                 damageIndicatorGui.StudsOffset = Vector3.new(offsetX, offsetY, offsetZ)
  36.                
  37.                 local damageIndicatorLabel = Instance.new("TextLabel")
  38.                
  39.                 damageIndicatorLabel.AnchorPoint = Vector2.new(0.5, 0.5)
  40.                 damageIndicatorLabel.Position = UDim2.new(0.5, 0, 0.5, 0)
  41.                
  42.                 damageIndicatorLabel.TextScaled = true
  43.                 damageIndicatorLabel.BackgroundTransparency = 1
  44.                 damageIndicatorLabel.Font = Enum.Font.GothamBlack
  45.                
  46.                 damageIndicatorLabel.Text = healthLost
  47.                
  48.                 damageIndicatorLabel.Size = UDim2.new(0, 0, 0, 0)
  49.                
  50.                 for damage, colour in pairs(damageForColours) do
  51.                    
  52.                     if healthLost <= damage then
  53.                        
  54.                         damageIndicatorLabel.TextColor3 = colour
  55.                         damage = 100
  56.                     end
  57.                 end
  58.                
  59.                 damageIndicatorLabel.Parent = damageIndicatorGui
  60.                
  61.                 damageIndicatorGui.Parent = char.HumanoidRootPart
  62.                
  63.                 damageIndicatorLabel:TweenSize(UDim2.new(1, 0, 1, 0), "InOut", "Quint", 0.3)
  64.                
  65.                
  66.                 wait(0.3)
  67.                
  68.                 local guiUpTween = tweenService:Create(damageIndicatorGui, tweenInfo, {StudsOffset = damageIndicatorGui.StudsOffset + Vector3.new(0, 1, 0)})
  69.                
  70.                 local textFadeTween = tweenService:Create(damageIndicatorLabel, tweenInfo, {TextTransparency = 1})
  71.                
  72.                 guiUpTween:Play()
  73.                 textFadeTween:Play()
  74.                
  75.                 game:GetService("Debris"):AddItem(damageIndicatorGui, 0.3)
  76.             end
  77.            
  78.             currentHealth = humanoid.Health
  79.         end)
  80.     end)
  81. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement