-
What do you want to achieve?
For our datastore to be actually saving and not removing itself out of thin air -
What is the issue?
DataStore Removing statistics of games Played and games Won -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
We are pretty new to DataStores and we did try to look for solutions on the Developer Hub.
Here is our GlobalDataStore which we made for Wins and games Played:
local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
game.Players.PlayerAdded:Connect(function(plr)
print("Player added:", plr.Name)
local success, err = pcall(function()
local plrkey = "id"..plr.UserId
local saveWins = plr.hiddenstats.Wins
local savePlayed = plr.hiddenstats.Played
local savedWins = ds:GetAsync(plrkey)
if savedWins then
saveWins.Value = savedWins
end
local playedKey = "played"..plr.UserId
local savedPlayed = ds:GetAsync(playedKey)
if savedPlayed then
savePlayed.Value = savedPlayed
end
end)
if not success then
warn("Error loading player data:", err)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
print("Player removing:", plr.Name)
local success, err = pcall(function()
local plrkey = "id"..plr.UserId
ds:SetAsync(plrkey, plr.hiddenstats.Wins.Value)
local playedKey = "played"..plr.UserId
ds:SetAsync(playedKey, plr.hiddenstats.Played.Value)
end)
if not success then
warn("Error saving player data:", err)
end
end)