How to change name of currency

Hello! I am making an ingame currency following a tutorial (Roblox Scripting Tutorial: How to Script a Currency System - YouTube), and I’ve just finished typing it. However, I want to change the currency name from “coins” to “cash”. How would I do this?
My current script is as below:


local DataStoreService = game:GetService("DataStoreService")
local CurrencyStore = DataStoreService:GetDataStore("CurrencyStore")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local UserId = Player.UserId
	local Currency = CurrencyStore:GetAsync(UserId)

	if Currency == nil then
		Currency = 0
		CurrencyStore:SetAsync(UserId, Currency)
	end

	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"

	local Coins = Instance.new("IntValue", Leaderstats)
	Coins.Name = "Coins"

	Coins.Value = Currency

	Coins.Changed:Connect(function(NewValue)
		CurrencyStore:SetAsync(UserId, NewValue)
	end)
end)

change the string value

from coins to cash

Also this is a really simple DataStore script, It constantly would send messages to update and cause a lot of errors, If you have a table of everyone’s currency then you would be able to change the value of the table, then when they leave, save their Data to their Datastores

Screen Shot 2021-03-13 at 10.25.36 AM
just change the string here to ‘Cash’
also, to make it more easier to read, change the ‘coins’ variable to ‘cash’ too.

HERE,
Screen Shot 2021-03-13 at 10.26.23 AM
HERE
Screen Shot 2021-03-13 at 10.26.14 AM
HERE,

Changing line 19 from

Coins.Name = "Coins"

to

Coins.Name = "Cash"

does nothing, it instead just doesn’t show it at all Screen Shot 2021-03-13 at 8.26.14 AM

You could try something along the lines of this

local PlayerData = {
	CurrencyStore = {}
}--Create PlayerData Table
local DataStoreService = game:GetService("DataStoreService")
local CurrencyStore = DataStoreService:GetDataStore("CurrencyStore")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local UserId = Player.UserId
	local Currency = CurrencyStore:GetAsync(UserId)

	if Currency == nil then
		Currency = 0
		PlayerData[UserId] = Currency--Set PlayerData instead of Datastore
	end

	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"

	local Cash = Instance.new("IntValue", Leaderstats)
	Cash.Name = "Cash"

	Cash.Value = Currency
	PlayerData.CurrencyStore[UserId] = Currency

	Cash.Changed:Connect(function(NewValue)
		PlayerData.CurrencyStore[UserId] = NewValue--Set PlayerData instead of Datastores
	end)
end)

Players.PlayerRemoving:Connect(function(player)
	local UserId = player.UserId
	CurrencyStore:SetAsync(UserId, PlayerData[player.UserId])--Save PlayerData
end)

How would I change the name of the currency using the method I am using?

EDIT: Actually, I found out what caused this. While I was working on this, My computer ran out of battery, and saved an auto recovery file. I forgot that I’d have to republish the game and allow API services. It works now!

I was just suggesting a different way to not put so much stress on the Roblox Servers. For you, whenever anyone got any money then it would send a message to the great datastore servers in roblox, which takes like a second or so.

1 Like

Change “Coins.Name = “Coins”” to your currency name

Change “Coins.Value” to the currency name

Change “Coins.Changed:Connect(function(NewValue)” to your currency
Only change “Coins”