How can I make this 1.000 into this 1k in a GUI?

Hello everyone, so I made a script that shows your cash value in a GUI, it works fine, but I was wondering if I could replace this:

image

Into this:

image

Heres the script:

while wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Cash.Text = "πŸ’²"..player:WaitForChild("leaderstats"):FindFirstChild("Cash").Value
end

If anybody could help me it would be wonderful, thank you!

There have been alot of threads like this earlier, please try to search before posting. But it can be done with some simple logic and maths like this:

local abbreviations = {
    "K",
    "M",
    "B", 
    "T", 
} --Your Abbreviations

local function Abbreviate(x)
    if x < 1000 then 
        return tostring(x)
    end

    local digits = math.floor(math.log10(x)) + 1
    local index = math.min(#abbreviations, math.floor((digits - 1) / 3))
    local front = x / math.pow(10, index * 3)

    return string.format("%i%s+", front, abbreviations[index])
end

print(Abbreviate(1000)) -- Should print 1K.
1 Like

Sorry, Im not a scripter so my programing skills are poor, and I dont know how to do certain things, and its one of my firsts times doing this, so I need help. And the output doesnt print β€œ1k”, it doesnt print nothing (I’ve added to my script)

What script is it? i mean a localscript / a server script. And can you show your latest script.

Its a local Script, and heres the lastest changes I’ve made to the script:

while wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Cash.Text = "πŸ’²"..player:WaitForChild("leaderstats"):FindFirstChild("Cash").Value
end


local abbreviations = {
	"K",
	"M",
	"B", 
	"T", 
} --Your Abbreviations

local function Abbreviate(x)
	if x < 1000 then 
		return tostring(x)
	end

	local digits = math.floor(math.log10(x)) + 1
	local index = math.min(#abbreviations, math.floor((digits - 1) / 3))
	local front = x / math.pow(10, index * 3)

	return string.format("%i%s+", front, abbreviations[index])
end

print(Abbreviate(1000)) -- Should print 1K.

Because your while loop is preventing the script from moving forward I recommend using :GetPropertyChangeSignal().

1 Like

if value / 1000000 > 1 then
Local temp = value *.0000001
Text = tempβ€¦β€œM”

How do I implement that in a script? I have never heard about that

local abbreviations = {
	"K",
	"M",
	"B", 
	"T", 
} --Your Abbreviations

local function Abbreviate(x)
	if x < 1000 then 
		return tostring(x)
	end

	local digits = math.floor(math.log10(x)) + 1
	local index = math.min(#abbreviations, math.floor((digits - 1) / 3))
	local front = x / math.pow(10, index * 3)

	return string.format("%i%s+", front, abbreviations[index])
end

while wait() do
	local player = game.Players.LocalPlayer
	local cash = Abbreviate(player:WaitForChild("leaderstats"):FindFirstChild("Cash").Value)
	script.Parent.Cash.Text = "πŸ’²"..cash
end
3 Likes
local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats"):FindFirstChild("Cash"):GetPropertyChangedSignal("Value"):Connect(function()

	script.Parent.Cash.Text = "πŸ’²"..player:WaitForChild("leaderstats"):FindFirstChild("Cash").Value
end)

This must fix it I might have made a typo I am on mobile sorry.

This also prevent unnecessary resource usage as this will run when the value changes while using a while loop runs constantly.

2 Likes