Hello, im trying to get an inventory system i made for a game to save but it only works about 50% of the time and the other 50% it gives me the error: "Invalid table key type used" when the local script fires the remote event or if using sever side scripts to bypass the remote event when it is saving. Here is one of the tables that the inventory script sends to the sever that causes the error
{{nil,nil,0,nil},{nil,nil,nil,nil},{nil,nil,nil,nil},{nil,nil,nil,nil},{nil,nil,nil,nil}}
(when there is a nil there is no item when there is a number there is an item. Items are saved as an ID so that's why there is an number.)
scrips that get errors:
The first one (Client sided)
function module.Moveitem(Row,SlotID,plr)
local ROW = Inventory[Row]
local IMGID = game.ReplicatedStorage.Items[ROW[SlotID]].ImageID.Value
if ROW[SlotID] ~= nil then
script.MouseDown.Value = true
repeat wait(0.1) until script.MouseDown.Value == false
if Inventory[LatestHover.X][LatestHover.Y] == nil then
Inventory[LatestHover.X][LatestHover.Y] = ROW[SlotID]
local IMGROW = script.Parent.Contens["Row" .. LatestHover.X]
IMGROW[LatestHover.Y].Image = "rbxassetid://" .. IMGID
IMGROW[LatestHover.Y].ImageTransparency = 0
IMGROW = script.Parent.Contens["Row" .. Row]
IMGROW[SlotID].ImageTransparency = 1
ROW[SlotID] = nil
---- Inventory = {{nil,nil,0,nil},{nil,nil,nil,nil},{nil,nil,nil,nil},{nil,nil,nil,nil},{nil,nil,nil,nil}}
game.ReplicatedStorage.Remoteevents.SaveItems:FireServer(Inventory) --- this line has the error
end
end
end
the script that handels the Remote event (Sever side form this point on):
game.ReplicatedStorage.Remoteevents.SaveItems.OnServerEvent:Connect(function(plr,inv)
local AACI = require(game.ServerScriptService.AAC.Inventory[plr.Name])
AACI.GetInventory(inv)
end)
The part of the script that the Remote event uses
function module.GetInventory(Inv)
print("Setting")
Inventory = Inv
end
The part that saves
function module.SaveToSever(plr)
print("Saving Inventory")
local DataStoreService = game:GetService("DataStoreService")
local Inventory_ = DataStoreService:GetDataStore("Inventory")
local Item = DataStoreService:GetDataStore("Items")
local key = "user_"..plr.userId
Item:SetAsync(key,Items)
for ROWID = 1,5 do
local Row = Inventory[ROWID]
for SLOTID = 1,4 do
if Row[SLOTID] ~= nil then
local HasItem = false
local ITEMID = Row[SLOTID]
for i,v in pairs(Items) do
if v[1] == ITEMID then
if v[3]+1 <= v[2] then
v[3] = v[3] +1
HasItem = true
end
end
end
if HasItem == false then
Row[SLOTID] = nil
end
end
end
end
Inventory_:SetAsync(key,Inventory)
end

2 comments
send your script
there is more then one script