local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local myDataStore = DataStore:GetDataStore("myDataStore")
local function addtoplayer(Player,v,i)
local value = game.Players.player.Inventory.otherValues
if i == 1 then value.formMastery.Value = v
elseif i == 2 then value.powerMastery.Value = v
elseif i == 3 then value.powerAlignment.Value = v
elseif i == 4 then value.Credits.Value = v
end
end
Players.PlayerAdded:Connect(function(player)
local playerName = player.Name
local Player = player
local newInventory = game.ServerStorage.Inventory:Clone()
newInventory.Parent = game.Players[playerName]
local id = "player_"..player.UserId
local data ={}
local s, e = pcall(function()
data = myDataStore:GetAsync(id)
end)
if s == true then
local value = game.Players[playerName].Inventory.otherValues
for i, v in pairs(data) do
local Player = player
if i == 1 or 2 or 3 or 4 then
addtoplayer(Player,v,i)
elseif i == 5 then
end
end
elseif s == false then
local value = math.random(1, 3)
local playerdefined = game.Players[player.Name]
playerdefined.Inventory.otherValues.powerMastery.Value = value
local value = math.random(1,7)
playerdefined.Inventory.otherValues.formMastery.Value = value
playerdefined.Inventory.otherValues.powerAlignment.Value = 0
playerdefined.Inventory.otherValues.Credits.Value = 100
end
end)
Players.PlayerRemoving:Connect(function(player)
local id = "player_"..player.UserId
local value = game.Players.player.Inventory.otherValues
local data ={}
table.insert(data,1,value.formMastery.Value)
table.insert(data,2,value.powerMastery.Value)
table.insert(data,3, value.powerAlignment.Value)
table.insert(data,4,value.Credits.Value)
local itemTable ={}
table.insert(data,5,itemTable)
myDataStore:SetAsync(id, data)
print("sucses")
end)
The error is one line #26 "bad argument #1 (table expected, got nil) The script is a pretty basic one just saving data and calling it back, the problem I have is when on line 26, it claims that data is nil and it expected a table, however according to what I understand data is a table?

5 comments
If the datastore is empty then it will return nil, if you didn't assign any value to the player's data then it will just set the variable data to nil
Doesn't the if s == true check this?
There's nothing in 'data'
"Doesn't the if s == true check this?"
No, it will not throw an error if the data is empty, it will only return nil