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:
Into this:
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.
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)
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.
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
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.