My datastores keep resetting.
This has happened 2 times now, it doesn’t really matter for now, but when I publish my game, I can’t have my datastores resetting.
I have no idea why this happens.
Script:
local dataStore = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrid = "id_"..plr.UserId
local save1 = plr.leaderstats.Goals
local save2 = plr.leaderstats.Wins
local save3 = plr.leaderstats.Coins
local save4 = plr.FirstPlay
local GetSaved = dataStore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
save3.Value = GetSaved[3]
save4.Value = GetSaved[4]
else
local NumberForSaving = {save1.Value, save2.Value, save3.Value, save4.Value}
dataStore:GetAsync(plrid,NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
dataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.Goals.Value, plr.leaderstats.Wins.Value, plr.leaderstats.Coins.Value, plr.FirstPlay.Value})
end)