local o=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local V=game:GetService("\082\117\110\083\101\114\118\105\099\101")local u=game:GetService("\080\108\097\121\101\114\115")if V:IsServer()then return{}end local K=u.LocalPlayer while not K do u.PlayerAdded:Wait()K=u.LocalPlayer end local G={}local A={}function A.createBillboardForAdornee(V,o)local u=G[o]if u then return u end u=Instance.new("\066\105\108\108\098\111\097\114\100\071\117\105")u.Name="\068\097\109\097\103\101\066\105\108\108\098\111\097\114\100\071\117\105"u.Adornee=o u.AlwaysOnTop=true u.ExtentsOffsetWorldSpace=Vector3.new(0,18,0)u.Size=UDim2.new(.42,20,15,0)u.ResetOnSpawn=false u.ZIndexBehavior=Enum.ZIndexBehavior.Sibling u.Parent=K.PlayerGui G[o]=u local A A=o.AncestryChanged:connect(function(V,u)if u==nil then A:disconnect()A=nil local V=G[o]V:Destroy()G[o]=nil end end)return u end function A.showDamageBillboard(K,V,u)if not V then return end u=math.ceil(u)local G=K:createBillboardForAdornee(V)local A=math.random(-10,10)/30 local w=Instance.new("\084\101\120\116\076\097\098\101\108")w.AnchorPoint=Vector2.new(.5,1)w.BackgroundTransparency=1 w.BorderSizePixel=0 w.Position=UDim2.fromScale(.5+A,1)w.Size=UDim2.fromScale(0,.25)w.Font=Enum.Font.FredokaOne w.Text=tostring(u)w.TextColor3=Color3.new(0,1,.498039)w.TextScaled=true w.TextStrokeTransparency=0 w.TextTransparency=0 w.TextXAlignment=Enum.TextXAlignment.Center w.TextYAlignment=Enum.TextYAlignment.Bottom w.Parent=G local L=TweenInfo.new(.5,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out,0,false,0)local N=o:Create(w,L,{Size=UDim2.fromScale(2,w.Size.Y.Scale),TextColor3=Color3.new(0,1,0)})local v=TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,.2)local e=o:Create(w,v,{Position=UDim2.fromScale(w.Position.X.Scale,.8),TextTransparency=1;TextStrokeTransparency=4;Rotation=math.random(-10,10)})local q q=e.Completed:connect(function()q:disconnect()q=nil w:Destroy()end)N:Play()e:Play()end return A
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

if RunService:IsServer() then return {} end

local localPlayer = Players.LocalPlayer
while not localPlayer do
	Players.PlayerAdded:Wait()
	localPlayer = Players.LocalPlayer
end

local adorneeToBillboardGui = {}

local DamageBillboardHandler = {}

function DamageBillboardHandler:createBillboardForAdornee(adornee)
	local billboard = adorneeToBillboardGui[adornee]
	if billboard then
		return billboard
	end

	billboard = Instance.new("BillboardGui")
	billboard.Name = "DamageBillboardGui"
	billboard.Adornee = adornee
	billboard.AlwaysOnTop = true
	billboard.ExtentsOffsetWorldSpace = Vector3.new(0,18,0)
	billboard.Size = UDim2.new(0.42,20,15,0)
	billboard.ResetOnSpawn = false
	billboard.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	billboard.Parent = localPlayer.PlayerGui
	adorneeToBillboardGui[adornee] = billboard

	local ancestorCon
	ancestorCon = adornee.AncestryChanged:connect(function(child, parent)
		if parent == nil then
			ancestorCon:disconnect()
			ancestorCon = nil

			local adorneeBillboard = adorneeToBillboardGui[adornee]
			adorneeBillboard:Destroy()
			adorneeToBillboardGui[adornee] = nil
		end
	end)

	return billboard
end

function DamageBillboardHandler:showDamageBillboard(adornee, damageAmount)
	if not adornee then return end
	damageAmount = math.ceil(damageAmount)

	local billboard = self:createBillboardForAdornee(adornee)

	local randomXPos = math.random(-10,10)/30
	
	local damageNumber = Instance.new("TextLabel")
	damageNumber.AnchorPoint = Vector2.new(0.5, 1)
	damageNumber.BackgroundTransparency = 1
	damageNumber.BorderSizePixel = 0
	damageNumber.Position = UDim2.fromScale(0.5 + randomXPos,1)
	damageNumber.Size = UDim2.fromScale(0,0.25)
	damageNumber.Font = Enum.Font.FredokaOne
	damageNumber.Text = tostring(damageAmount)
	damageNumber.TextColor3 = Color3.new(0, 1, 0.498039)
	damageNumber.TextScaled = true
	damageNumber.TextStrokeTransparency = 0
	damageNumber.TextTransparency = 0
	damageNumber.TextXAlignment = Enum.TextXAlignment.Center
	damageNumber.TextYAlignment = Enum.TextYAlignment.Bottom
	damageNumber.Parent = billboard

	local appearTweenInfo = TweenInfo.new(
		0.5, --time
		Enum.EasingStyle.Elastic,
		Enum.EasingDirection.Out,
		0, --repeatCount
		false, --reverses
		0) --delayTime
	local appearTween = TweenService:Create(
		damageNumber,
		appearTweenInfo, {
			Size = UDim2.fromScale(2, damageNumber.Size.Y.Scale),
			TextColor3 = Color3.new(0, 1, 0)
		}
	)

	local upTweenInfo = TweenInfo.new(
		0.5, --time
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0, --repeatCount
		false, --reverses
		0.2) --delayTime
	local upTween = TweenService:Create(
		damageNumber,
		upTweenInfo, {
			Position = UDim2.fromScale(damageNumber.Position.X.Scale, 0.8),
			TextTransparency = 1,
			TextStrokeTransparency = 4,
			Rotation = math.random(-10,10)
		}
	)

	local completedCon
	completedCon = upTween.Completed:connect(function()
		completedCon:disconnect()
		completedCon = nil
		damageNumber:Destroy()
	end)

	appearTween:Play()
	upTween:Play()
end

return DamageBillboardHandler
