Hi there, for some reasson the data saving doesn’t work like its suppose to, it only saves sometimes and when it doesn’t save it doesn’t give me an error message or anything, the output stays blank and i dont know what i did wrong.
Heres the data save script:
function LevelSave(Player)
local success = nil
local errormessage = nil
local attempts = 1
repeat
success, errormessage = pcall(function()
MDS:SetAsync(Player.UserId.."-Level", Player.leaderstats.Level.Value)
end)
attempts += 1
if not success then
warn(errormessage)
task.wait(1)
end
until success or attempts >= 5
if success then
print("< LevelData successfully saved >")
else
print("< LevelData failed to save >")
warn(errormessage)
end
end
Heres the full script:
local DSS = game:GetService("DataStoreService")
local MDS = DSS:GetDataStore("MDS")
local CheckXpEvent = game.ReplicatedStorage:WaitForChild("Events").RemoteEvents.CheckXp
function LevelData(Player)
--//Create Level Values\\--
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
Level = Instance.new("IntValue", leaderstats)
Level.Name = "Level"
Level.Value = 1
Xp = Instance.new("IntValue", Player)
Xp.Name = "Xp"
Xp.Value = 0
reqXp = Instance.new("IntValue", Player)
reqXp.Name = "reqXp"
reqXp.Value = Level.Value * 200
--//Data\\--
local data
local success, errormessage = pcall(function()
data = MDS:GetAsync(Player.UserId.."-Level")
end)
if success then
print("< LevelData successfully loaded >")
Level.Value = data
else
print("< LevelData failed to load >")
warn(data)
end
end
function LevelSave(Player)
local success = nil
local errormessage = nil
local attempts = 1
repeat
success, errormessage = pcall(function()
MDS:SetAsync(Player.UserId.."-Level", Player.leaderstats.Level.Value)
end)
attempts += 1
if not success then
warn(errormessage)
task.wait(1)
end
until success or attempts >= 5
if success then
print("< LevelData successfully saved >")
else
print("< LevelData failed to save >")
warn(errormessage)
end
end
And yes, i am calling the functions in an game.Players.PlayerAdded:Connect(LevelData)
and game.Players.PlayerRemoving:Connect(LevelSave)