The code you posted
local function defaultData()
return {
Inventory = {} -- example
} -- return default data
end
local loadedData
local JobId = game.JobId
local success, message = pcall(function(
datastore:UpdateAsync(key, function(data)
if data == nil then
return defaultData() -- return your default data
end
print("Current SessionJobId: " .. tostring(data.SessionJobId))
-- Check if the save doesn't have a session lock or is this session
if data.SessionJobId == nil or data.SessionJobId == game.JobId then
data.SessionJobId = JobId -- set the session ID with current session ID
-- Handle fetching or overwriting here
loadedData = data -- take the data out
return data
end
-- otherwise, session is locked, so return nil to indicate that
end)
end)
if success and data then
-- handle loaded data
end
If i return nil in UpdateAsync because the data is sessionlocked does that wipe the data and make it nil?