Hey everyone,
I'm asking this question again because the last time I did, barely anyone answered. So basically, I want this script to update consistently so that whenever the value changes, the textlabel updates. I tried using a while loop at the bottom, but that didn't solve the problem, either.
Here's the scripts
ModuleScript in ReplicatedStorage
local AbbreviateNumber = {}
local abbreviations = {
K = 4,
M = 7,
B = 10,
T = 13,
Qa = 16,
Qi = 19
}
function AbbreviateNumber:Abbreviate(number)
local text = tostring(math.floor(number))
print(#text)
local chosenAbbreviation
for abbreviation, digits in pairs(abbreviations)do
if #text >= digits and #text < (digits + 3) then
chosenAbbreviation = abbreviation
break
end
end
if chosenAbbreviation then
local digits = abbreviations[chosenAbbreviation]
print(chosenAbbreviation)
print(digits)
local rounded = math.floor(number / 10 ^ (digits - 2)) * 10 ^ (digits - 2)
text = string.format("%.1f", rounded / 10 ^ (digits - 1))..chosenAbbreviation
else
text = number
end
return text
end
return AbbreviateNumber
LocalScript inside of the TextLabel
local moneyvalue = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Money")
local number = moneyvalue.Value
local moneytext = script.Parent
local AbbreviateNumber = require(game.ReplicatedStorage.AbbreivateNumber)
while wait() do -- I tried using a while loop, but the text doesn't update.
local text = AbbreviateNumber:Abbreviate(number)
moneytext.Text = text
end
Anyone know how to fix this issue? Thanks!

1 comment
I'm not sure what the script would look like, but I believe the solution is for it to detect a change in the value of the variable. When it detects this change it will re-run the script. Of course the detection process would have to be continues, so you would have to utilize loops. If anyone knows what the code looks like I'm sure Lazokk would love it.