The Set Async doesn’t work, he don’t warn an error in Output, I don’t know what I did it wrong. Anyone can help me?
Script
local module = require(game.ServerStorage.Modules:WaitForChild('Status'))
local DSS = game:GetService('DataStoreService')
local StatusData = DSS:GetDataStore('asdasdasd')
game.Players.PlayerAdded:Connect(function(plr)
-- [CREATING INSTANCES]
local StatusF = Instance.new('Folder', plr)
StatusF.Name = 'Status'
module.CreateStatus('Strength', StatusF)
module.CreateStatus('Defense', StatusF)
module.CreateStatus('Stamina', StatusF)
module.CreateStatus('Speed', StatusF)
-- [STATUS LOAD]
local s, cS = pcall(function()
return StatusData:GetAsync(plr.UserId)
end)
print(cS)
if s then
if cS ~= nil then
for _, v in pairs(StatusF:GetChildren()) do
if v:IsA('IntValue') then
print('Foi')
v.Value = cS[v.Name]
end
end
end
else
StatusData:SetAsync(plr.UserId, nil)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
-- [PICK UP INSTANCES]
local StatusF = plr.Status
-- [STATUS SAVE]
local T = module.PickStatus(StatusF)
local s, e = pcall(function()
if StatusData:GetAsync(plr.UserId) == nil then
StatusData:SetAsync(plr.UserId, nil)
StatusData:UpdateAsync(plr.UserId, T)
else
StatusData:UpdateAsync(plr.UserId, T)
end
end)
if s then
print('Data Saved')
else
warn(e)
end
end)
Module Script
local module = {}
function module.CreateStatus(Name, Parent)
local NewStatus = Instance.new('IntValue', Parent)
NewStatus.Name = Name
NewStatus.Value = 100
end
function module.PickStatus(folder)
local t = {
['Strength'] = folder.Strength.Value;
['Speed'] = folder.Speed.Value;
['Defense'] = folder.Defense.Value;
['Stamina'] = folder.Stamina.Value;
}
return t
end
return module