Hi, I’m trying to format currencies using this module. It doesn’t format, instead, it gives the value. Here is my code:
local DataStore2 = require(game.ServerScriptService.DataStore2)
local MarketplaceService = game:GetService("MarketplaceService")
local FormatNumber = require(game.ServerScriptService.FormatNumber)
local defaultCashValue = 0
game.Players.PlayerAdded:Connect(function(plr)
local coinsDataStore = DataStore2("Coins", plr)
local cash = Instance.new("IntValue")
cash.Name = "Cash"
local function coinsUpdated(updatedValue)
cash.Value = coinsDataStore:Get(updatedValue)
game.ReplicatedStorage.UpdateClientCurrency:FireClient(plr, coinsDataStore:Get(defaultCashValue))
FormatNumber.FormatCurrency(updatedValue, "$")
end
coinsUpdated(defaultCashValue)
coinsDataStore:OnUpdate(coinsUpdated)
end)
Hey with DataStore2 You’re updating the data store, which then updates the value.
Say you want special formatting to appear then I recommend instead of using an IntValue, use a StringValue.
Then on your CoinsUpdated function instead of it just being
You can add this on, cash.Value = coinsDataStore:Get(updatedValue)…“$”
So say you’re coinsDataStore is 500, the cash.value formatting will now have it appear as 500$
Now say you want it so, “I want 1000$ to appear as 1,000$”. You will need to run checks on what the current coinsdatastore is, for example for every three 0’s add a “,”. To my knowledge this works perfectly for me since when this function is called it is editing the “cash.Value” which is a String Value.
However I must apologise that I am unaware of what “FormatNumber.FormatCurrency” is as I have personally never seen this in the ds2 module before, I hope what I posted above fixed your issue!
That’s odd. Since it’s now a String Value you should be able to make it Format, and appear how you want. (As the “Cash” Value). Does the DollarSign not appear after the numbers? e.g Instead of 500 it would now be “500$”
So the CurrentCash Variable will be the holder for your coinsDataStore amount, If this players coin store had 500 then CurrentCash would be 500. Then for formatting I am turning this variable from integer to string using “tostring(variable)” with adding “…$” afterwards, essentially i am forcing it to be a string. Which would make the current Formatting variable have “500$”, then afterwards I am changing the Cash String Value to be what the Formatting Variable is, this means everytime your coinsDataStore has an update to it, it will run this function which should hopefully make Cash appear with an “$” at the end.