My data store is refusing to save for some unknown reason. Any help?
Here is my script
local playersleft = 0
local datas = game:GetService("DataStoreService"):GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
playersleft = playersleft + 1
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local exp = Instance.new("IntValue",leaderstats)
exp.Name = "Exp"
local maxexp = Instance.new("IntValue",leaderstats)
maxexp.Name = "MaxExp"
maxexp.Value = 100
local level = Instance.new("IntValue",leaderstats)
level.Name = "Level"
local toonys = Instance.new("IntValue",leaderstats)
toonys.Name = "Toonys"
game.ReplicatedStorage.Events.LevelOneGive.Event:Connect(function()
toonys.Value = toonys.Value + math.random(10,20)
exp.Value = exp.Value + 10
end)
game.ReplicatedStorage.Events.LevelTwoGive.Event:Connect(function()
toonys.Value = toonys.Value + math.random(20,30)
exp.Value = exp.Value + 20
end)
game.ReplicatedStorage.Events.LevelThreeGive.Event:Connect(function()
toonys.Value = toonys.Value + math.random(30,40)
exp.Value = exp.Value + 30
end)
local success, problem = pcall(function()
datas:GetAsync(player.UserId)
end)
if success then
print("Data collected!")
level.Value = datas
toonys.Value = datas
exp.Value = datas
else
print("New player!")
level.Value = 1
toonys.Value = 0
exp.Value = 0
end
wait(2)
local success, problem = pcall(function()
datas:SetAsync(player.UserId)
end)
if success then
print("Saved!")
else
print("Error")
end
wait(1)
if not success then
local success2, problem2 = pcall(function()
datas:SetAsync(player.UserId)
end)
if success2 then
print("Second save complete!")
else
print("Error 2")
end
end
end)

1 comment
It is printing "Error" like ii told it to if there is an error but it's supposed to print "Saved"