local I=game:GetService("\080\108\097\121\101\114\115")local K=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local Y={}local l={}function l.createBillboardGui(K,I)local l=Y[I]if l then return l end l=Instance.new("\066\105\108\108\098\111\097\114\100\071\117\105")l.Name="\068\097\109\097\103\101\066\105\108\108\098\111\097\114\100\071\117\105"l.Adornee=I l.AlwaysOnTop=true l.MaxDistance=60 l.Size=UDim2.new(10,20,10,20)l.ExtentsOffsetWorldSpace=Vector3.new(0,1,0)l.ResetOnSpawn=false l.ZIndexBehavior=Enum.ZIndexBehavior.Sibling l.Parent=I Y[I]=l local C C=I.AncestryChanged:connect(function(K,l)if l==nil then C:disconnect()C=nil local K=Y[I]K:Destroy()Y[I]=nil end end)return l end function l.tweenBillboard(Y,I)local l=TweenInfo.new(1,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out,0,false,0)local C=K:Create(I,l,{Size=UDim2.fromScale(.1,.1),TextColor3=Color3.new(1,1,1)})local g g=C.Completed:connect(function()g:disconnect()g=nil I:Destroy()end)C:Play()end function l.showDamageBillboard(Y,I,K)I=math.ceil(I)local l=Y:createBillboardGui(K)local C=math.random(1,9)/10 local g=Instance.new("\084\101\120\116\076\097\098\101\108")g.AnchorPoint=Vector2.new(.5,1)g.BackgroundTransparency=1 g.BorderSizePixel=0 g.Position=UDim2.fromScale(C,.5)g.Size=UDim2.fromScale(.01,.01)g.Font=Enum.Font.SourceSansBold g.Text="-"..tostring(I)g.TextColor3=Color3.new(.7,.7,.7)g.TextScaled=true g.TextWrapped=true g.TextStrokeTransparency=0 g.TextTransparency=0 g.TextXAlignment=Enum.TextXAlignment.Center g.TextYAlignment=Enum.TextYAlignment.Bottom g.Parent=l Y:tweenBillboard(g)end return l
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

local adorneeToBillboardGui = {}

local DamageBillboard = {}

function DamageBillboard:createBillboardGui(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.MaxDistance = 60
	billboard.Size = UDim2.new(10,20,10,20)
	billboard.ExtentsOffsetWorldSpace = Vector3.new(0,1,0)
	billboard.ResetOnSpawn = false
	billboard.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	billboard.Parent = adornee
	--billboard.Parent = Players.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 DamageBillboard:tweenBillboard(textLabel)
	local appearTweenInfo = TweenInfo.new(
		1, --time
		Enum.EasingStyle.Elastic,
		Enum.EasingDirection.Out,
		0, --repeatCount
		false, --reverses
		0) --delayTime
	local appearTween = TweenService:Create(
		textLabel,
		appearTweenInfo, {
			Size = UDim2.fromScale(0.1, 0.1),
			TextColor3 = Color3.new(1,1,1)
		}
	)
	
	local completedCon
	completedCon = appearTween.Completed:connect(function()
		completedCon:disconnect()
		completedCon = nil
		textLabel:Destroy()
	end)

	appearTween:Play()
end

function DamageBillboard:showDamageBillboard(damageAmount, adornee)
	damageAmount = math.ceil(damageAmount)

	local billboard = self:createBillboardGui(adornee)
	
	local randomXPos = math.random(1, 9) / 10
	
	local textLabel = Instance.new("TextLabel")
	textLabel.AnchorPoint = Vector2.new(0.5, 1)
	textLabel.BackgroundTransparency = 1
	textLabel.BorderSizePixel = 0
	textLabel.Position = UDim2.fromScale(randomXPos,0.5)
	textLabel.Size = UDim2.fromScale(0.01, 0.01)
	textLabel.Font = Enum.Font.SourceSansBold
	textLabel.Text = "-" .. tostring(damageAmount)
	textLabel.TextColor3 = Color3.new(0.7, 0.7, 0.7)
	textLabel.TextScaled = true
	textLabel.TextWrapped = true
	textLabel.TextStrokeTransparency = 0
	textLabel.TextTransparency = 0
	textLabel.TextXAlignment = Enum.TextXAlignment.Center
	textLabel.TextYAlignment = Enum.TextYAlignment.Bottom
	textLabel.Parent = billboard
	
	self:tweenBillboard(textLabel)
end

return DamageBillboard
