#Just wondering if someone could help me format my leaderstats number and the textlabel number

1 messages · Page 1 of 1 (latest)

tropic zephyr
#

Could you elaborate on what you mean by "format"

#

Also send code

safe lichen
tropic zephyr
safe lichen
#

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

tropic zephyr
#
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

safe lichen
#

do I just add that to my script or do I need a module to go with it

tropic zephyr
#

Uhhh either or works

#

Its just a function

#

If you plan on using it in other scripts then module

safe lichen
#

hmm I dont think I set it up right