Hello there, I am trying to make a data store in my game so I can save the player's data when they rejoin (definition of a data store). I'm new to data stores, as this is my first time using them. This actually used to work when I was just saving the currency for the game and not survivals. Then I tried figuring out how to save two things for the next 20 minutes. I get no errors at all so I don't know how to fix it. Can somebody please tell me what's wrong?
local DataStore = game:GetService("DataStoreService"):GetDataStore("LavaData")
local CurrencyName = "Smackaroons"
--Seeing if a player is addded
game.Players.PlayerAdded:Connect(function(player)
--leaderstats
wait(1.5)
local save1 = player.leaderstats.Survivals
local save2 = player.leaderstats.Smackaroons
local Id = "DataSaving-"..player.UserId
local savedData1 = nil
local savedData2 = nil
--data saving
pcall(function()
savedData1 = DataStore:GetAsync(Id)
savedData2 = DataStore:GetAsync(Id)
end)
--Checking if this is not nil
if savedData1 and savedData2 ~= nil then
save1.Value = savedData1
save2.Value = savedData2
print("Data Loaded")
print(Id)
else
--If the player is new
save1.Value = 0
save2.Value = 0
print("New Player")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
--When player leaves
local Id = "DataSaving-"..player.UserId
DataStore:SetAsync("DataSaving-"..player.UserId,{player.leaderstats.Survivals.Value,player.leaderstats.Smackaroons.Value})
end)
game:BindToClose(function()
--When the last player in the server leaves and the server is empty, to save it when server shuts down
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This server is shutting down, join any other server or wait")
end
end
wait(5)
end)

3 comments
This was helpful, but it did not work
I didn't get any errors though, strange
Put multiple print function in some places. Let me know where it is not printing