Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i shorten the coins in my GUI ?

I am making a clicking game and i want if someone gets coins like 1,000 i want it to show like 1k

How do i change this:

local player = game.Players.LocalPlayer
local textlabel = script.Parent:WaitForChild("PCoins")

while wait() do
	textlabel.Text = player:WaitForChild("leaderstats"):WaitForChild("Coin").Value
end

3 answers

1st: check if money is higher than one thousand (if money > 1000 then)

2nd: do this math (math.floor(money/100)/10) and concatenate with "K"

Example of what conversion should look like this way:

Example money = 1245.5

Money shown on GUI = 1.2K

If you don't want to show decimals do (math.floor(money/1000)) instead.

1 comment

0

oof, feel dumb cuz, before I knew about math.floor function I use if statements for this

local K=1000
local M=1000000
local B=M*K
local T=B*K
local Q=T*K
 
while wait() do
local player=game.Players.LocalPlayer
local Tclick=player:WaitForChild("leaderstats",60).Clicks.Value

if Tclick/K>=1 and Tclick<M then
script.Parent.Text=tostring(Tclick/K):sub(1,5).. "K Clicks"
elseif Tclick/M>=1 and Tclick<B then
script.Parent.Text=tostring(Tclick/M):sub(1,5).. "M Clicks"
elseif Tclick/B>=1 and Tclick<T then
script.Parent.Text=tostring(Tclick/B):sub(1,5).. "B Clicks"
elseif Tclick/T>=1 and Tclick<Q then
script.Parent.Text=tostring(Tclick/T):sub(1,5).. "T Clicks"
elseif Tclick/Q>=1 and Tclick<Q*K then
script.Parent.Text=tostring(Tclick/Q):sub(1,5).. "Q Clicks"
else
script.Parent.Text=tostring(Tclick).. " Clicks"
end
end

this uses a decimal point, but still show like k thing.

Simplest way to do this is by doing while wait loop checking. Instead of using while wait() do in your script use Instance:GetChangedPropertySignal Read more here:

Example Script:

local player = game.Players.LocalPlayer
local suffixes = { -- your number suffix
	"K",
	"M",
	"B",
	"T",
	"Qd",
	"Qn"
}

player:WaitForChild("leaderstats").Coin:GetChangedPropertySignal("Value"):Connect(function()
	local number = player:WaitForChild("leaderstats").Coin.Value -- your number here
	local count = 0 -- used for code below
	
	while number / 1000 >= 1 do
		number = number / 1000
		count = count + 1
	end
	
	if count == 0 then
		script.Parent.Text = number 
		return false
	else
		script.Parent.Text = string.format("%.2f", number/10*10) .. suffixes[count] -- "%.2f" means 2 decimals after the whole number
	end
end

The idea of this script is that the script will divide your number until it's not greater or equal to 1. Then the script will choose an appropriate suffix for the number.

This discussion is preserved as it was. New answers, comments, and votes are closed.