#Inventory System

1 messages · Page 1 of 1 (latest)

thick minnow
#

This is the script for the inventory system

#

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

chrome mason
thick minnow
#

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

chrome mason
thick minnow
#

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"
}

burnt salmonBOT
#

studio** You are now Level 6! **studio

thick minnow
#

So when i try to add it there is no value

chrome mason
thick minnow
#

But i'm not getting an error on the line which makes the value = 1

thick minnow
#

I thought it was just saying it couldn'

#

couldn't add it

#

Let me check what the nil is you're right

chrome mason
#

so it doesnt exist

#

i think..

#

try to print it or do something else with it to check its value

#

or manually check it

last summit
#

wait

#

what is the problem

chrome mason
thick minnow
#

Player inventory is not nil

#

Prints this

#

Ill try playerinventory[item]

last summit
thick minnow
#

Yeah its the item

#

Oh i've just realized

last summit
#

Did you fix it?

thick minnow
#

No

thick minnow
last summit
#

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

thick minnow
#

Alright

#

It just completley removes the item

#

keeps the non stacklable items but doesnt store the stackable one

last summit
#

`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`

thick minnow
#

ill try this soon doing something rn

thick minnow
#

It worked a little different then I expected but it works

#

Thanks