Hi, I made a datastore for my game now that autosaves, and isn’t dependent on the button anymore, for some reason my data won’t save when I come back, in studio it printed the data saved message but I still didn’t see my data.
Thanks In Advance
local DSS = game:GetService("DataStoreService")
local rc = DSS:GetDataStore("RebirthsSave")
local lc = DSS:GetDataStore("Levels")
local qc = DSS:GetDataStore("PlayerQuests")
local gs = DSS:GetDataStore("GemsSave")
local ss = DSS:GetDataStore("SpeedValues")
game.Players.PlayerAdded:Connect(function(Plr)
local leader = Instance.new("Folder", Plr)
leader.Name = "leaderstats"
local levels = Instance.new("IntValue", leader)
levels.Name = "Levels"
levels.Value = 1
local Rebirths = Instance.new("IntValue", leader)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local Gems = Instance.new("IntValue", leader)
Gems.Name = "Gems"
Gems.Value = 0
local questFolder = Instance.new("Folder", Plr)
questFolder.Name = "Quests"
local quest1 = Instance.new("BoolValue", questFolder)
quest1.Name = "Quest1"
quest1.Value = false
local quest2 = Instance.new("BoolValue", questFolder)
quest2.Name = "Quest2"
quest2.Value = false
local quest3 = Instance.new("BoolValue", questFolder)
quest3.Name = "Quest3"
quest3.Value = false
local quest4 = Instance.new("BoolValue", questFolder)
quest4.Name = "Quest4"
quest4.Value = false
local quest5 = Instance.new("BoolValue", questFolder)
quest5.Name = "Quest5"
quest5.Value = false
local quest6 = Instance.new("BoolValue", questFolder)
quest6.Name = "Quest6"
quest6.Value = false
local quest7 = Instance.new("BoolValue", questFolder)
quest7.Name = "Quest7"
quest7.Value = false
local quest8 = Instance.new("BoolValue", questFolder)
quest8.Name = "Quest8"
quest8.Value = false
local quest9 = Instance.new("BoolValue", questFolder)
quest9.Name = "Quest9"
quest9.Value = false
local quest10 = Instance.new("BoolValue", questFolder)
quest10.Name = "Quest10"
quest10.Value = false
local quest11 = Instance.new("BoolValue", questFolder)
quest11.Name = "Quest11"
quest11.Value = false
local quest12 = Instance.new("BoolValue", questFolder)
quest12.Name = "Quest12"
quest12.Value = false
local quest13 = Instance.new("BoolValue", questFolder)
quest13.Name = "Quest13"
quest13.Value = false
local data = qc:GetAsync(Plr.UserId)
if data then
quest1.Value = data['Quest1']
quest2.Value = data['Quest2']
quest3.Value = data['Quest3']
quest4.Value = data['Quest4']
quest5.Value = data['Quest5']
quest6.Value = data['Quest6']
quest7.Value = data['Quest7']
quest8.Value = data['Quest8']
quest9.Value = data['Quest9']
quest10.Value = data['Quest10']
quest11.Value = data['Quest11']
quest12.Value = data['Quest12']
quest13.Value = data['Quest13']
else
quest1.Value = false
quest2.Value = false
quest3.Value = false
quest4.Value = false
quest5.Value = false
quest6.Value = false
quest7.Value = false
quest8.Value = false
quest9.Value = false
quest10.Value = false
quest11.Value = false
quest12.Value = false
quest13.Value = false
local data1
local data2
local data3
local data4
local success, errormessage = pcall(function()
data1 = rc:GetAsync(Plr.UserId.."-rebirths")
data2 = lc:GetAsync(Plr.UserId.."-levels")
data3 = gs:GetAsync(Plr.UserId.."-gems")
data4 = ss:GetAsync(Plr.UserId.."-speedvalue")
end)
if success then
print("Player data found!")
else
warn(errormessage)
end
end
end)
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.Quests:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local queue = 0
game.Players.PlayerRemoving:Connect(function(Player)
queue +=1
local success, errormessage = pcall(function()
rc:SetAsync(Player.UserId.."-rebirths", Player.leaderstats.Rebirths.Value)
lc:SetAsync(Player.UserId.."-levels", Player.leaderstats.Levels.Value)
gs:SetAsync(Player.UserId.."-gems", Player.leaderstats.Gems.Value)
ss:SetAsync(Player.UserId.."-speedvalue",Player.Data.attackspeed.Value)
local plrstats = create_table(Player)
qc:SetAsync(Player.UserId, plrstats)
end)
if success then
print("Data Saved!")
queue -= 1
else
warn(errormessage)
end
end)
game:BindToClose(function()
repeat wait() until queue == 0
end)