So i am trying to get datastore to work and i have done it many times before and i am using the same setup for the saving and loading of the data the weird part is that all the times i’ve used my script so far i’ve never ever had any issues as in the title i have checked so many times and it simply rarely saves it seams to be like 1 out of 10 or so that works but the loading of the data works just fine
here is my script
local datastore = game:GetService("DataStoreService")
local key = 2
local MainStore = datastore:GetDataStore("Main")
local failed = {}
local datastoreOn = true
local eternity = require(game.ReplicatedStorage.EternityNum.EternityNum)
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder", player)
stats.Name = "stats"
-- stats --
local statA = Instance.new("StringValue", stats)
statA.Name = "statA"
statA.Value = "0"
local stat1 = Instance.new("StringValue", stats)
stat1.Name = "stat1"
stat1.Value = table.concat(eternity.convert(0), ",")
local stat2 = Instance.new("StringValue", stats)
stat2.Name = "stat2"
stat2.Value = table.concat(eternity.convert(0), ",")
if datastoreOn then
local dataMain
local succes, errorMessage = pcall(function()
dataMain = MainStore:GetAsync(tostring(player.UserId).."Main"..tostring(key)) -- works!
end)
if dataMain then
if tonumber(dataMain[1]) + 3 == #dataMain then
statA.Value = dataMain[1]
stat1.Value = dataMain[2]
stat2.Value = dataMain[3]
for i = 1, tonumber(statA.Value), 1 do
local stat = Instance.new("StringValue", stats)
stat.Name = "stat"..(i + 2)
stat.Value = dataMain[i + 3]
end
end
elseif not succes then
failed[player.Name] = player.Name
player:Kick("Your data was not recieved from server please rejoin")
end
end
if not failed[player.Name] then
for i = 1, tonumber(statA.Value) + 1, 1 do
local section = game.ReplicatedStorage.Models.Section:Clone()
section:SetPrimaryPartCFrame(CFrame.new(i * 20 - 20, 0.5, 0))
section.Parent = workspace.Map
section.Name = "section"..tostring(i)
section.Button.Type.Value = tostring(i)
section.Button.Button.BrickColor = BrickColor.Random()
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if datastoreOn then
if not (failed[player.Name]) then
local main = {}
main[1] = player.stats.statA.Value
main[2] = player.stats.stat1.Value
main[3] = player.stats.stat2.Value
for i = 1, tonumber(player.stats.statA.Value), 1 do
main[i + 3] = player.stats:FindFirstChild("stat"..(i + 2))
end
pcall(function()
MainStore:SetAsync(tostring(player.UserId).."Main"..tostring(key), main) -- does not work!
end)
else
failed[player.Name] = nil
end
end
end)
I’ve been debugging this for hours and the only way i can see that it is wrong is just roblox being drunk for the millioth time. No errors in console