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)

1 comment
In the instance when I was trying to fix this I put yum in the brackets to see if that will work that's why its there on line 11