How to make format number for health gui of a NPC

How do I make the NPC’s health text (the numbers) look that the picture?


Do I combine this scripts. If so , how do I combine these scripts so the NPC health is abbreviate in the NPC health ui

The script is in the NPC Head UI

local Folder = game.Workspace.NPC --Location of NPCs
local function bindDummy(EachNPC) --Start fuction
local Head = EachNPC:FindFirstChild("Head") --Looks NPC Head
local HeadUI = Head.HeadUI.UI.HealthUI --Location of UI
local Humanoid = HeadUI.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") --Looks for Humanoid
HeadUI.HealthNum.Text = math.floor(Humanoid.Health) .. " / " .. math.floor(Humanoid.MaxHealth) --Math of NPC health
local function updateHealth() --start fuction
HeadUI.HealthNum.Text = math.floor(Humanoid.Health) .. " / " .. math.floor(Humanoid.MaxHealth) --Math of NPC health
local pie = (Humanoid.Health / Humanoid.MaxHealth) --Math of NPC health
HeadUI.Healthbar.Size = UDim2.new(pie, 0, 1, 0) --Moves Healthbar
task.wait(0.4) --Wait
HeadUI.Redbar.Size = UDim2.new(pie, 0, 1, 0) --Moves RedBar
end --End function
Humanoid.HealthChanged:Connect(updateHealth) --Connect function (updateHealth)
end --End function
for _, EachNPC in pairs(Folder:GetChildren()) do -- Bind all existing dummies
bindDummy(EachNPC)
end --End for
Folder.ChildAdded:Connect(bindDummy) -- Bind all future dummies

The script is in ReplicatedStroage

local abbreviator = {}

local suffixes = {"K", "M", "B", "T", "Qd", "Qn" , "Sx" , "Sp", "O", "N"} -- Abbreviation changes every additional 3 integer in a number

function abbreviator:AbbreviateNumbers(value)
	local negative = (tonumber(value) or 0) < 0
	if negative then
		value = -(value)
	end
	if not (tonumber(value)) or tonumber(value) <= 999 then
		return value
	end
	local str = value
	for i = 1, #suffixes do
		if tonumber(value) < 10 ^ (i * 3) then
			str = math.floor(value / ((10 ^ ((i - 1) * 3)) / 100)) / 100 .. suffixes[i - 1]
			break
		end
	end
	if str and negative then str = "-"..str end
	return str
end

return abbreviator

I forget what it’s called, but there is a library specifically designed for abbreviating numbers, let me see if I can find it

This is one example, but there are plenty more on the roblox devforum, you may be able to find another more suitable for your needs. Hope I helped.

Ok I did it thank you Den_vers!! I look into it and mad it work!!!

local replicatedStorage = game:GetService("ReplicatedStorage") --Gets ReplicatedStorage
local formatNumber = require(replicatedStorage:WaitForChild("FormatNumber").Simple) --Looks for Simple
HeadUI.HealthNum.Text = formatNumber.FormatCompact(math.floor(Humanoid.Health)) .. " / " .. formatNumber.FormatCompact(math.floor(Humanoid.MaxHealth)) --Math of NPC health

Nice! But Cyber would you mind marking me as the solution, because I provided you with the library!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.