I am currently making a game that heavily relies on currency items, and I wanted to make exclusive content for another currency. The main currency are jewels that you can obtain throughout the game, and there is another one called “Voids.”
Voids are used to purchase items that are exclusive to this type of currency, and not with jewels. However, I’m having a heavily hard time on trying to implement this into my game.
What do you want to achieve?
I want to make two currencies work alongside each other without conflicting in-game GUI’s.
What is the issue?
As stated above, I want to make two currencies work with each other, but they keep conflicting with one another. The two currencies keep conflicting one another, as shown in this GUI.
What solutions have you tried so far?
I have tried going onto multiple scripting forums, as well as going onto YouTube and trying to look up my problem. Nothing has worked and I am incredibly stumped. Additional help would be extremely appreciated.
I am new to scripting, so please try to keep it as simple as possible when explaining!
This is the Jewels currency, labeled as ‘Gold’ in the script to make it easier for me to remember.
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue")
stats.Parent = player
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Gold"
if CashStore:GetAsync("Points_"..player.Name) ~= nil then
cash.Value = CashStore:GetAsync("Points_"..player.Name)
else
cash.Value = 0
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..player.Name, Val)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered)
This is the other script I’m trying to work with the Jewels currency, and I thought that it’d work- it didn’t.
VoidStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue")
stats.Parent = player
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Voids"
if VoidStore:GetAsync("Points_"..player.Name) ~= nil then
cash.Value = VoidStore:GetAsync("Points_"..player.Name)
else
cash.Value = 0
end
cash.Changed:connect(function(Val)
VoidStore:SetAsync("Points_"..player.Name, Val)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered)
One immediate problem I’ve spotted is that you’ve created leader stats twice, (once in each script). You need to create that only once and put the 2 IntValue instances into it.
Change Points_ for void to “Void”
and Points_ for gold to “Gold”
I don’t work with data store often so I don’t know if you have to declare it first or if you can just declare it like vie done above. but try it anyway
(and obvs your going to need to split that if statement into 2 individual ones for Gold and Void)
What do you mean by splitting the if statement into 2 individual ones? Like I said, I’m new to scripting so it can be a bit hard to follow along. My apologies.
Sorry about all of that. I really do appreciate all the help, I’m gonna try and use this script really quick! Thank you so much. I’ll use this as a way to learn more.
If there is something wrong with the GUI’s, I’ll look into it - nonetheless, thank you so much!
One reason it might not have been working is because we were using new data stores. so its going to be 0 by defult but i dont know why the other ones showing n/a tho, make sure that ones linked to leaderstats.Gold.Value and the other one is leaderstats.Void.Value
Thank you for all of your help, but unfortunately it’s still not working. I tweaked the GUI’s to match with the script you made, putting the script into the ServerScriptService, and allowing it to run on a test. Nothing didn’t work.
Again, thank you for all the help- this may help somebody if they were to search up what I was going through. : )
This doesn’t work because CashStore:GetAsync("Points_"..player.Name) ~= nil then is always nil because you never set “Points_” try removing that if statement with its end
Did you create something inside of the Voids? Are you sure you didn’t mean .Name?
void.Name = "Voids" -- This looks correct to me.
Your code should look something like this.
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue")
stats.Parent = player
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Gold"
local void = Instance.new("IntValue")
void.Parent = stats
void.Name = "Voids"
if CashStore:GetAsync("GOLD"..player.Name) ~= nil then
cash.Value = CashStore:GetAsync("GOLD"..player.Name)
else
cash.Value = 0
end
if CashStore:GetAsync("VOID"..player.Name) ~= nil then
void.Value = CashStore:GetAsync("VOID"..player.Name)
else
void.Value = 0
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("GOLD"..player.Name, Val)
end)
void.Changed:connect(function(Val)
CashStore:SetAsync("VOID"..player.Name, Val)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered)
I would recommend that you save data using player.UserId instead of player.Name. Players can change their usernames and would lose their data. I didn’t change it for the purpose of keeping your experience working. There are lots of things I would change in this script. However, it might go beyond your topic. If you would like me to give you more advice, send me a message on DevForum.
On top of this, in the future I would look into saving players data in a table when using roblox data stores, this is more efficient and will result in less data store requests entering the queue which could result in some users losing their currency.