I use Zednov’s Tycoon Kit, but it’s changed a bit. There is a ‘StringValue’ named ‘Cash’ with however much cash the player has in leaderstats. But the problem is, it is a StringValue to make it K+, M+, B+, etc (thousands, millions, billions). How do I check if 1.1K+ is, for example, 1153 in Cash? I want to know how to change the K+, M+, B+, etc to the actual NumberValue instead of it being a string.
Sorry if the above wasn’t clear, if you have any questions I’ll answer them.
local abbreviations = {
K = 10^3,
M = 10^6,
B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
if str:sub(#str,#str) == i then
num = tonumber(str:gsub(i,"")) * v
break
end
end
print(num) -- 1100 ?
I wrote it in devforum so it may not be that good but go check it.
local abbreviations = {
K = 10^3,
M = 10^6,
B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
if str:sub(#str,#str) == i then
local n,t = str:gsub(i,"")
num = tonumber(n)*v
break
end
end
print(num) -- 1100 ?
Error: “Attempt to get length of an Instance Value”
if str:sub(#str,#str) == i then
I think it errors because the variable abbreviations is wrong. The cash is K+ it has a + on it. I do not know how to change that as it will not allow it in the variables because it thinks I am adding something…
local abbreviations = {
K = 10^3,
M = 10^6,
B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
if str:sub(#str.Value,#str.Value) == i then
local n,t = str.Value:gsub(i,"")
num = tonumber(n)*v
break
end
end
print(num) -- 1100 ?