Hi, Can some one please help me? i try to save and load my data in the playerdatastore. but i dont know what is wrong with it, and as i see nothing is wrong at all. i dont get errors but also my data wont save and or load. i looked up a tutorial and did every thing they say in it, put api on on site and every thing, but still not working.
Please help!
so i have this code:
local currencyNameA = "Coins"
local currencyNameB = "Gold"
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlrDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currencyA = Instance.new("IntValue")
currencyA.Name = currencyNameA
currencyA.Parent = folder
local currencyB = Instance.new("IntValue")
currencyB.Name = currencyNameB
currencyB.Parent = folder
local aID = currencyNameA.."_"..player.UserId
local bID = currencyNameB.."_"..player.UserId
local asavedData = nil
local bsavedData = nil
pcall(function()
asavedData = DataStore:GetAsync(aID)
bsavedData = DataStore:GetAsync(bID)
end)
if asavedData ~= nil and bsavedData ~= nil then
currencyA.Value = asavedData
currencyB.Value = bsavedData
print("Data loaded")
else
-- New Player
currencyA.Value = 0
currencyB.Value = 0
print("New Player to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local aID = currencyNameA.."_"..player.UserId
local bID = currencyNameB.."_"..player.UserId
DataStore:SetAsync(aID,player.leaderstats[currencyNameA].Value)
DataStore:SetAsync(bID,player.leaderstats[currencyNameB].Value)
print("Data saved")
end)
game:BindToClose(function()
-- When game is ready to shutdown
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down or restarting!")
end
end
wait(5)
end)

1 comment
I think in lines 20 and 21 you Should use
currencyA.NameandcurrencyB.Namebecause those are the name of the int values but not the name of any particular variable