I’m running into a weird situation. This only seems to occur on mobile devices. But when they are in the lobby and change some type of value, for instance what unit is selected, it doesn’t seem to save it.
- This happens when they are in the lobby,
- Then changed the selected units,
- They get teleported to a Private Server
- Before they changed anything it doesn’t load.
Load Data if any:
local selectedData = {}
for _, npcItem in pairs(SelectedUnits:GetChildren()) do
table.insert(selectedData, {id = npcItem.Name, name = npcItem:FindFirstChild("Name").Value, level = npcItem:FindFirstChild("Level").Value})
end
Save Data entry:
if SelectedUnits then
local selectedData = {}
for _, npcItem in pairs(SelectedUnits:GetChildren()) do
table.insert(selectedData, {
id = npcItem.Name,
name = npcItem:FindFirstChild("Name").Value,
level = npcItem:FindFirstChild("Level").Value
})
end
local tries = 0
local success
repeat
tries = tries + 1
success = pcall(function()
SelectedUnitsStore:SetAsync(player.UserId, selectedData)
--print("SelectedUnits Saved")
print("Saved for: "..player.Name.. " userid: "..player.UserId.." --------")
end)
if not success then wait(1) end
until tries == 3 or success
if not success then
warn("Cannot save data for player: "..player.Name.. " userId: "..player.UserId)
else
-- DATA WAS SAVED
end
end
However, on my pc, when I log into that alt account and try it on there it works perfectly fine. I get no errors, when I print the table of units selected before they leave during the SaveData function it prints all of them properly.
I save during these instances:
BindToClose or Player is leaving.
**Edit if I wait long enough for the auto-save to kick in while they are in the lobby it saves correctly…