#Just wondering if someone could help me format my leaderstats number and the textlabel number
1 messages · Page 1 of 1 (latest)
What I ment was like I wanted my thing to say 1k rather than 1000
Oh you need to do some math on the number you are given
could you help me out
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats" -- naming
local clicks = Instance.new("StringValue", leaderstats)
clicks.Name = "Total Clicks"
clicks.Value = 0
end)
local clickedRemote = game.ReplicatedStorage.Clicked
clickedRemote.OnServerEvent:Connect(function(player)
print(player.Name .. "button clicked")
local leaderstats = player:FindFirstChild("leaderstats")
local clicks = leaderstats:FindFirstChild("Total Clicks")
clicks.Value += 1
end)
Ithis is where the value is plused
local suffixes = {"K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc"}
local function formatNumber(n)
if n < 1000 then
return tostring(n)
end
local suffixIndex = math.floor(math.log(n, 1000))
suffixIndex = math.min(suffixIndex, #suffixes) -- clamp to available suffixes
local divided = n / (1000 ^ suffixIndex)
-- Format to max 2 decimal places, trimming trailing zeros
local formatted = string.format("%.2f", divided)
formatted = formatted:gsub("%.?0+$", "") -- remove trailing zeros/dot
return formatted .. suffixes[suffixIndex]
end
Here is the number converter code that adds a suffix
do I just add that to my script or do I need a module to go with it
Uhhh either or works
Its just a function
If you plan on using it in other scripts then module
hmm I dont think I set it up right