Hi there!
So I have a screenGUI is being used to purchase in game items. It comes up and works fine, that is until the player gains too much money.
Im also using a script that converts long to short currency for the leaderboard stats and it adds commas as needed (1,000) and "10K 10M 10B, K,M and B.
So this issue Im having: if the player has a comma or letter in their "Cash", the purchase script will error out as it does not know what to do with anything but numbers.
So if player has $10050 they can buy a $10 item, but $10,050 we get a nil error. Same with letters.
The conversion is done in a settings module in the workspace seen below, it works fine and makes everything look nice, only now I have this issue.
So, I can remove this and just run with numbers only and it will work, but then it just doesn't look as nice.
function module:ConvertComma(num)
local x = tostring(num)
if #x>=10 then
local important = (#x-9)
return x:sub(0,(important))..","..x:sub(important+1,important+3)..","..x:sub(important+4,important+6)..","..x:sub(important+7)
elseif #x>= 7 then
local important = (#x-6)
return x:sub(0,(important))..","..x:sub(important+1,important+3)..","..x:sub(important+4)
elseif #x>=4 then
return x:sub(0,(#x-3))..","..x:sub((#x-3)+1)
else
return num
end
end
function module:ConvertShort(Filter_Num)
local x = tostring(Filter_Num)
if #x>=10 then
local important = (#x-9)
return x:sub(0,(important)).."."..(x:sub(#x-7,(#x-7))).."B+"
elseif #x>= 7 then
local important = (#x-6)
return x:sub(0,(important)).."."..(x:sub(#x-5,(#x-5))).."M+"
elseif #x>=4 then
return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
else
return Filter_Num
end
end
and here is an example of the purchasing script: (localscript)
local Settings = require(game.workspace.Settings) >>I added this after to see if it would help, but no.
local plr = game.Players.LocalPlayer
local backpack = game.Players.LocalPlayer.Backpack
local tool = game.ReplicatedStorage.Cinnabun
script.Parent.MouseButton1Click:Connect(function()
if tonumber(plr.leaderstats.Cash.Value) >= 5 then
if not plr:FindFirstChild("Cinnabun", true) and not plr.Character:FindFirstChild "Cinnabun" then
plr.leaderstats.Cash.Value = tonumber(plr.leaderstats.Cash.Value) - 5
tool:Clone().Parent = plr.Backpack
end
end
end)
If there are any suggestions you may have or if you have run into this issue any thought would be much appreciated!
Cheers!

1 comment
This is my first post, I cleaned up the formatting a bit now. Thanks for the suggestion, I will attempt to implement a string pattern!