My datastore wont save and i dont know why. There’s no errors either.
Code:
local player = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local DataStore = dss:GetDataStore("MimiSaveSytem")
player.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local stage = Instance.new("IntValue")
stage.Name = "Wins"
stage.Parent = stats
local data = DataStore:GetAsync(plr.UserId)
if data then
print(data.Wins)
for _,stat in pairs(stats:GetChildren()) do
stat.Value = data[stat.Name]
end
else
print(plr.Name .. " has no data")
end
end)
local function savePlrData(plr)
local success,err = pcall(function()
DataStore:UpdateAsync(plr.UserId, function(currentVal)
return currentVal
end)
end)
if not success then return err end
end
player.PlayerRemoving:Connect(function(plr)
savePlrData(plr)
end)
game:BindToClose(function()
for _,plr in pairs(player:GetPlayers()) do
savePlrData(plr)
end
end)
Here are the solutions i tried:
- (code that i took from my now deleted topic which doesn’t work correctly anymore too)
local function savePlrData(plr)
local success,err = pcall(function()
DataStore:UpdateAsync(plr.UserId, function()
local saveData = {}
for i, data in pairs(plr.leaderstats:GetChildren()) do
saveData[data.name] = data.Value
end
DataStore:UpdateAsync(plr.UserId, saveData)
end)
end)
if not success then return err end
end
- idk why i did this-
local function savePlrData(plr)
local success,err = pcall(function()
DataStore:UpdateAsync(plr.UserId, function(currentVal)
return newval
end)
end)
if not success then return err end
end