OK, it keeps saying the error
Failed to get Moyfe's inventory, perhaps a new player? Reason:
08:51:46.283 - ServerScriptService.serverScripts.dataStore.saveItems:35: ServerScriptService.serverScripts.dataStore.saveItems:13: bad argument #1 to 'pairs' (table expected, got no value)
08:51:46.283 - Stack Begin
08:51:46.283 - Script 'ServerScriptService.serverScripts.dataStore.saveItems', Line 35
08:51:46.284 - Stack End
08:51:46.284 - ServerScriptService.serverScripts.dataStore.saveItems:13: bad argument #1 to 'pairs' (table expected, got no value)
08:51:46.284 - Stack Begin
08:51:46.284 - Script 'ServerScriptService.serverScripts.dataStore.saveItems', Line 13
08:51:46.285 - Stack End
Could not save Moyfe's inventory, reason:
08:51:50.125 - ServerScriptService.serverScripts.dataStore.saveItems:52: 103: Dictionary is not allowed in DataStore
08:51:50.125 - Stack Begin
08:51:50.126 - Script 'ServerScriptService.serverScripts.dataStore.saveItems', Line 52
08:51:50.126 - Stack End
This is my script:
local ds = game:GetService("DataStoreService"):GetOrderedDataStore("Main")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name="leaderstats"
local grasscut = Instance.new("IntValue",leaderstats)
grasscut.Name = "Grass Cut"
local money = Instance.new("IntValue",leaderstats)
money.Name = "Money"
local tableOfItems = {}
local s,f=pcall(function()
for i,v in pairs(ds:GetAsync(player.UserId)) do
tableOfItems[#tableOfItems+1]=v
end
end)
if s then
for i,v in pairs(tableOfItems) do
if v.Name=="Banned" then
if v==true then
player:Kick()
end
end
if v.Name=="grasscut" then
grasscut.Value = v
end
if v.Name=="items" then
for i,v in pairs(v) do
game.ServerStorage.Items[v]:Clone().Parent = player.Backpack and player.StarterGear
end
end
end
else
print("Failed to get "..player.Name.."'s inventory, perhaps a new player? Reason:")
error(f)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {}
for i,v in pairs(player.StarterGear:GetChildren()) do
items.insert(v.Name)
end
local itemsToSave={["banned"]=false,["grasscut"]=player.leaderstats["Grass Cut"].Value,["items"]=items,["money"]=player.leaderstats.Money.Value}
local s,f=pcall(function()
ds:SetAsync(player.UserId,itemsToSave)
end)
if s then
print(player.Name.."'s inventory has been saved!")
else
print("Could not save "..player.Name.."'s inventory, reason:")
error(f)
end
end)
Can somebody please tell me my mistake? Was it the tables? I'm not sure.
