#Inventory System
1 messages · Page 1 of 1 (latest)
This is the error
It works 100% fine when an item isn't stackable
However when it is, it does not make the item = 1
is this error from the code u sent
yes
Here is the output
Longswords are not stackable so they are seperate
But when i create the first smithing template, it does not make the value 1
well it says you are adding a nil value with a number, so you first need to find what is the nil
It's the fact that the smithing template isn't equal to 1
Hold on let me try explain it better
Basically this line
Creates the item and supposed to make it equal to 1
So
Inventory = {
Item = 1
}
But right now it just makes the item
Inventory = {
"Item"
}
** You are now Level 6! **
So when i try to add it there is no value
so wouldnt this mean thata the nil is PlayerInventory.Inventory?
But i'm not getting an error on the line which makes the value = 1
Oh wait i completley misunderstood it
I thought it was just saying it couldn'
couldn't add it
Let me check what the nil is you're right
it couldnt add it because PlayerInveotory is a nil value
so it doesnt exist
i think..
try to print it or do something else with it to check its value
or manually check it
read above
i see
Did you fix it?
No
But is Item supposed to be a number^
DataStoreFolder.AddInventory.OnServerInvoke = function(Player, Item)
local Key = tostring(Player)
local PlayerInventory = playerData[Key]["Slot_" .. tostring(Player:GetAttribute("Slot"))].Inventory
local Stackable = InventoryModule.Items[Item].Stackable
if Stackable then
if PlayerInventory[Item] then
PlayerInventory[Item] += 1
else
PlayerInventory[Item] = 1
end
else
table.insert(PlayerInventory, Item)
end
end
try ts
Alright
It just completley removes the item
keeps the non stacklable items but doesnt store the stackable one
`DataStoreFolder.AddInventory.OnServerInvoke = function(Player, Item)
local Key = tostring(Player)
local Slot = "Slot_" .. tostring(Player:GetAttribute("Slot"))
local PlayerInventory = playerData[Key][Slot].Inventory
local Stackable = InventoryModule.Items[Item].Stackable
if Stackable then
local found = false
for _, entry in ipairs(PlayerInventory) do
if entry.Name == Item then
entry.Amount += 1
found = true
break
end
end
if not found then
table.insert(PlayerInventory, {Name = Item, Amount = 1})
end
else
table.insert(PlayerInventory, {Name = Item})
end
end`
ill try this soon doing something rn