Hi, I am having issues with my leaderstats. I have a datastore for money. It all works perfectly. So, I decided to duplicate the script and change money to gems and renamed the datastore to GEMSDataStore. Issue is the leaderstats only display one of the currency and I want it to display both.
Code:
local DSS = game:GetService("DataStoreService") local DataStore = DSS:GetDataStore("GEMSDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("yum") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Gem = Instance.new("IntValue") Gem.Name = "Gem" Gem.Parent = leaderstats local data local success, errorMessage = pcall(function() data = DataStore:GetAsync(player.UserId) end) if success and data ~= nil then print("Data successfully loaded!") Gem.Value = data.Gem else warn(errorMessage) end end) game.Players.PlayerRemoving:Connect(function(player) local leaderstats = player.leaderstats local data = { Gem = leaderstats.Gem.Value; } local success, errorMessage = pcall(function() DataStore:SetAsync(player.UserId,data) end) if success then print("Data successfully saved!") else warn(errorMessage) end end)
I tested and it worked, put a Normal Script in the ServerScriptService
local DSS = game:GetService("DataStoreService") local CashData = DSS:GetDataStore("CashData") local GemsData = DSS:GetDataStore("GemsData") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local cash = Instance.new("IntValue", leaderstats) cash.Name = "Cash" local gems = Instance.new("IntValue", leaderstats) gems.Name = "Gems" local playerId = "Player_"..player.UserId local cashdata local gemsdata local success, errormessage = pcall(function() cashdata = CashData:GetAsync(playerId) gemsdata = GemsData:GetAsync(playerId) end) if success then cash.Value = cashdata gems.Value = gemsdata end end) game.Players.PlayerRemoving:Connect(function(player) local playerId = "Player_"..player.UserId local cashdata = player.leaderstats.Cash.Value local gemsdata = player.leaderstats.Gems.Value local success, errormessage = pcall(function() CashData:SetAsync(playerId, cashdata) GemsData:SetAsync(playerId, gemsdata) end) if success then print("Saved") else print("There was an error") warn(errormessage) end end)