As you can tell it multiplies the damage number after a single shot. A headshot does 100 and any other limb does 32 but instead of adding up after 2 it just doubles the real number. I believe it is the if statement but not too sure why…
Why are you cloning the DamageNumber in ReplicatedStorage?
If you take off :Clone() don’t you get the same value?
Forgive my ignorance, but is DamageNumber.TextLabel.Text = tostring(damage)
selecting the variable damage? If so how is damage set because you are using it in your calculation in the broken section?
Try printing all your variables in the bottom section to see which variable breaks the formula:
if humanoid.Parent.Head:FindFirstChild('DamageNumber') then
print( "Text: ", DamageNumber.TextlLabel.Text , " damage: ", damage)
DamageNumber.TextLabel.Text = tostring(tonumber(DamageNumber.TextLabel.Text + damage)) -- Breaks
end
damage is the damage sent to the server. the gui for the indicator is cloned from the replicated storage to the hit target when the remote event is fired to the player who shot the target. The event fire to the player is giving the client the amount of damage the user did aswell as the targeted player for the parent of the cloned gui
local DamageNumber = game:GetService('ReplicatedStorage').DamageNumber:Clone()
DamageNumber.Parent = humanoid.Parent.Head
DamageNumber.TextLabel.Text = tostring(damage)
--FindFirstChild returns the already existing DamageNumber, but then it doesn't get saved anywhere
if humanoid.Parent.Head:FindFirstChild('DamageNumber') then
--This just adds the new damage to itself and sets the label text
DamageNumber.TextLabel.Text = tostring(tonumber(DamageNumber.TextLabel.Text + damage))
end
heres what I think you meant to do:
-- = nil is optional but the linter will complain otherwise
local DamageNumber = nil
--Check if there's already a damage number
DamageNumber = humanoid.Parent.Head:FindFirstChild('DamageNumber')
if DamageNumber == nil then
--There isn't one, make one now
DamageNumber = game:GetService('ReplicatedStorage').DamageNumber:Clone()
else
--There is one, add to it
damage += tonumber(DamageNumber.TextLabel.Text)
end
--This line is Idempotent if DamageNumber already existed
DamageNumber.Parent = humanoid.Parent.Head
DamageNumber.TextLabel.Text = tostring(damage)