I'm trying to create a script that makes damage numbers pop up(billboard GUIs) when a humanoid has taken damage, what I am doing currently is this: note that I have defined all variables *v is the humanoid of the characters
v.Changed:connect(function (p)
if (p == "Health") then
print(v.health)
local delta = h - v.Health
if delta >= 1 then
local gui = script:WaitForChild("HurtGui"):clone()
gui.Parent = v.Parent:FindFirstChild("Torso")
gui.Adornee = gui.Parent
gui.StudsOffsetWorldSpace = Vector3.new(math.random(xoffset*2)-xoffset,math.random(yoffset*2)-yoffset,math.random(zoffset*2)-zoffset)
gui:WaitForChild("TextLabel").Text = "" .. delta
wait(1)
gui:Destroy()
end
h = v.Health
end
end)
I think it's pretty inefficient and I am still getting bugs like large numbers popping up when the humanoid didn't take that much damage.
How would I fix this?

3 comments
what is 'v'
o sorry v is the humanoid
I would changed that function to the Humanoid.HealthChanged function, and see where you go from there.