I’m having issues where my number either updates too slow or incorrectly, I’m not too sure which or if either but any help would be apricated.
https://gyazo.com/b5ac3889d61069a7f6f1df0709c76414
ServerScript
CHECKLIST
-Hitbox w Indicator
DamageIndicator (script)
--]]
local rep = game:WaitForChild("ReplicatedStorage")
local SwordDamageHandler = rep.WeaponEvents.SwordDamageHandler
local hum = script.Parent.Parent:FindFirstChildWhichIsA("Humanoid") or script.Parent:FindFirstChildWhichIsA("Humanoid")
local no = false
local OldHealth = hum.Health
hum.HealthChanged:Connect(function(CurrentHealth)
if CurrentHealth < OldHealth then
local minus = OldHealth - CurrentHealth
print("Current / Old"..CurrentHealth, OldHealth.."Calc"..minus)
local ColourValue = nil
local Calculated = math.round(minus)
print(Calculated)
if Calculated < 10 then ColourValue = Color3.new(0.792157, 0.270588, 0.278431)
elseif Calculated <= 20 and Calculated >= 10 then
ColourValue = Color3.new(0.792157, 0.188235, 0.2)
elseif Calculated <= 50 and Calculated >= 20 then
ColourValue = Color3.new(0.792157, 0.129412, 0.141176)
elseif Calculated <= 100 and Calculated >= 50 then
ColourValue = Color3.new(0.792157, 0, 0.0117647)
elseif Calculated <= 200 and Calculated >= 100 then
ColourValue = Color3.new(1, 0, 0.0156863)
else ColourValue = Color3.new(0, 0, 0)
end
local DamageInd = Instance.new("TextLabel")
DamageInd.Parent = script.Parent.Indicator
DamageInd.Name = "Damage"
DamageInd.BackgroundTransparency = 1
DamageInd.Size = UDim2.new(0, 50, 0, 50)
DamageInd.TextColor3 = ColourValue
DamageInd.TextScaled = true
local X = math.random(25, 75) / 100
local Y = math.random(25, 75) / 100
DamageInd.Text = "-"..tostring(Calculated)
DamageInd.Visible = true
DamageInd.Position = UDim2.new(X, 0, Y, 0)
--print(X,Y)
local label = DamageInd -- The reference to the label
local ts = game:GetService("TweenService")
local tweenI = TweenInfo.new(5, Enum.EasingStyle.Quad)
local goals = {Position = UDim2.fromScale(X, -0.5)}
local tweenmove = ts:Create(label, tweenI, goals)
--^^^^^Making damage indicator move^^^^^--
local halth = hum.Health
local timeToFade = 2
local object = DamageInd
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {}
goal.TextTransparency = 1
local tweenfade = ts:Create(object, tweenInfo, goal)
tweenmove:Play()
tweenfade:Play()
tweenfade.Completed:Connect(function()
DamageInd:Destroy()
OldHealth = CurrentHealth
end)
elseif CurrentHealth > OldHealth then
local plus = math.round(CurrentHealth - OldHealth)
local ColourValue = nil
local Calculated = plus
print(Calculated)
if Calculated < 10 then ColourValue = Color3.new(0.654902, 0.792157, 0.596078)
elseif Calculated <= 20 and Calculated >= 10 then
ColourValue = Color3.new(0.615686, 0.792157, 0.698039)
elseif Calculated <= 50 and Calculated >= 20 then
ColourValue = Color3.new(0.623529, 0.792157, 0.576471)
elseif Calculated <= 100 and Calculated >= 50 then
ColourValue = Color3.new(0.443137, 0.792157, 0.380392)
elseif Calculated <= 200 and Calculated >= 100 then
ColourValue = Color3.new(0.337255, 1, 0.290196)
else ColourValue = Color3.new(0.14902, 1, 0)
end
local DamageInd = Instance.new("TextLabel")
DamageInd.Parent = script.Parent.Indicator
DamageInd.Name = "Damage"
DamageInd.BackgroundTransparency = 1
DamageInd.Size = UDim2.new(0, 50, 0, 50)
DamageInd.TextColor3 = ColourValue
DamageInd.TextScaled = true
local X = math.random(25, 75) / 100
local Y = math.random(25, 75) / 100
DamageInd.Text = "+"..tostring(Calculated)
DamageInd.Visible = true
DamageInd.Position = UDim2.new(X, 0, Y, 0)
--print(X,Y)
local label = DamageInd -- The reference to the label
local ts = game:GetService("TweenService")
local tweenI = TweenInfo.new(5, Enum.EasingStyle.Quad)
local goals = {Position = UDim2.fromScale(X, -0.5)}
local tweenmove = ts:Create(label, tweenI, goals)
--^^^^^Making damage indicator move^^^^^--
local halth = hum.Health
local timeToFade = 2
local object = DamageInd
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {}
goal.TextTransparency = 1
local tweenfade = ts:Create(object, tweenInfo, goal)
tweenmove:Play()
tweenfade:Play()
tweenfade.Completed:Connect(function()
DamageInd:Destroy()
OldHealth = CurrentHealth
print("Regenerating")
end)
end
end)