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

How to make a Value like 1000 to 1K into a text ?

So I've been trying to make A Value like a cash from 1000 to 1K into a text button and I don't know how, now why I need it? To money display gui to make it shorter

Here my script :

while wait() do
game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Cash:" .. game.Players.LocalPlayer.leaderstats.Cash.Value
end

2 answers

✓ Accepted answer
function sortText(num)
	local values = {{1000, "K+"}, {1000000, "M+"}, {1000000000, "B+"}}
	local str = ""
	if type(num) ~= "number" then num = tonumber(num) end
	for i = 1, #values do
		if num >= values[i][1] then
			str = (math.floor(num / values[i][1]))..values[i][2]
		end
	end
	return (num < 1000 and num or str)
end

This should do the trick. You can add more if you'd like, but I doubt you'd need to go above a billion.

Don't forget to accept the answer if it is what you were looking for!

2 comments

0

But how I make it into the text?

0

It already comes in text, you would just have to call the function.

I'm not entirely sure on that, I've tried before to see if there was a better algorithm myself, but this is the best I can think of for Simple

local placeTables = {1000, 10000, 100000, 1000000}
local placeLetter = {
	[placeTables[1, 3]] =  "k";
	[placeTables[4]] = m;
};
local player = game:GetService("Players")
local guiLabel = Player.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel
local cashValue = Player.leaderstats.Cash.Value
while guiLabel do
	if cashValue = placeTables[1,4] then
		for_,Letter in ipairs(placeLetter) do
			if cashValue == Letter then
				guiLabel.Text = "Cash: "..cashValue..Letter
			end
		end
	end
end

There's a high probability this won't work;/

3 comments

0

Did this not work?

0

No. This code is completely invalid.

0

"There's a high probability this won't work;/", Sorry, brains fried rn, at least i tried right, I knew what I was writing was bull;)

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