I’m creating a money system where when a player joins an IntValue is inserted into the player and a gui automatically updates every 5 seconds as the intValue.Value, I want to make it so that if a player had their intvalue set to 5000 in the gui it would format as 5,000. Normally I would go to the wiki for information before coming here, but I cannot understand basically anything the wiki had to say. Would love to know.
1 Like
Are you sure baout that? That would be expensive. Why not use the GetPropertyChnagedSignal
?
Anyways, have you thought about how much currency a player can accumulate?
1 Like
thanks for telling me about changedsignal I would really appreciate you telling me how to format the script
--Local script, under the gui
local name = game.Players.LocalPlayer.Name
local IntValue = [The IntValue folder]:FindFirstChild(name)
IntValue:GetPropertyChnagedSignal("Value"):Connect(function()
script.Parent.Text = IntValue.Value
end)
i dont think you understood the topic at all…
Here’s a useful webpage for formatting numbers:
http://lua-users.org/wiki/FormattingNumbers
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
1 Like
Micro-optimized 'cause I was bored:
function comma_value(amount)
local formatted, k = amount, nil
local a, b = "^(-?%d+)(%d%d%d)", '%1,%2'
repeat
formatted, k = string.gsub(formatted, a, b)
until (k == 0)
return formatted
end
I appreciate your response but I found a neat module by @gillern that formats numbers and it works really nicely