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