-
What do you want to achieve? Keep it simple and clear!
I want to save data to and autosave slot for my game. -
What is the issue? Include screenshots / videos if possible!
When I:SetAsync
, it does not update the datastore.
Data that gets saved:
Data when loaded:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
No solutions found.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Before you ask:
- Yes, I checked if it’s using the correct player ID
- I have API services on
Problematic code:
local function PlayerAdded(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local dollars = Instance.new("IntValue")
dollars.Name = "Dollars"
dollars.Parent = leaderstats
local rp = Instance.new("IntValue")
rp.Name = "RP"
rp.Parent = leaderstats
leaderstats.Parent = player
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
local data
data = database:GetAsync(player.UserId)
return data
end)
attempt += 1
if not success then
warn(playerData)
task.wait(3)
end
until success or attempt == 5
if success then
print("Connected to database", playerData)
if not playerData then
print("Assigning default data")
playerData = {
["Dollars"] = 10000000,
["RP"] = 0,
["ShipSaves"] = {}
}
elseif playerData.ShipSaves.AutoSave then
print("Loading autosave data")
local plot_folder
repeat plot_folder = MS.get_plot(player)
task.wait()
until plot_folder ~= nil
plot_folder = plot_folder.Objects
MS.placeObjects(playerData.ShipSaves.AutoSave, plot_folder)
print("Autosave data loaded")
end
sessionData[player.UserId] = playerData
else
warn("Unable to get data for", player.Name)
player:Kick("Unable to load your data. Try again later.")
end
dollars.Value = sessionData[player.UserId].Dollars
dollars:GetPropertyChangedSignal("Value"):Connect(function()
sessionData[player.UserId].Dollars = dollars.Value
end)
rp.Value = sessionData[player.UserId].RP
rp:GetPropertyChangedSignal("Value"):Connect(function()
sessionData[player.UserId].RP = rp.Value
end)
end