Hello! I have tried to create a double-currency system, with two different kinds of currencies but in the same script. As of now, I attempted to make the first one work due to not being loaded when the game starts, even if it saves. If you could, I would also love if you helped me in making another currency in the same script, thank you.
local currencyName = "¥"
local DataStore = game:GetService("DataStoreService"):GetDataStore("MoneyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local playerID = ""..player.UserId
local savedData = nil
local savedData = DataStore:GetAsync(playerID)
if savedData ~= nil then
print("loaded"..currency.Value)
currency.Value = savedData
else
print("hi")
currency.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerID = currencyName.."coin-"..player.UserId
DataStore:SetAsync(playerID, player.leaderstats[currencyName].Value)
print("saved "..player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick()
end
end
wait(5)
end)

4 comments
You forgot to create the two values to save, I think, lmao
Unfortunately it doesn't seem to be working, I will answer to my post with the script I came up with.
Unfortunately it doesn't seem to be working, I will answer to my post with the script I came up with.
Put it into a Pcall function.