Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

inventory folder is empty so i cant use it as a table?

Asked by 1 year ago

I put a folder in players on add when people join to act as a inventory, so when i am wanting to add an item into it, i first try to use for, i v inpairs to make sure the item isn't in inventory first but when i put inventory into the like this

for i, v in pairs(plr.Inventory)

i keep getting error saying inventory is an instance. I figure its considered an instance since there isnt any items in the inventory yet so i am not sure how to get around this. I don't want to just add an item into the persons inventory when they join because what if they sold every item in their inventory later and got a item, then the script would break. here is full code.

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("InventoryData")

game.Players.PlayerAdded:Connect(function(p)

    local invFolder = Instance.new("Folder", p)
    invFolder.Name = "Inventory"

end)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, item) -- put this item into plr inv folder
    print(item.Name)
    local list = game.ReplicatedStorage.items:GetChildren()
    for i, v in pairs(list) do
        local y = v
        if y.Name == item.Name then
            for i, v in pairs(plr.Inventory) do --mess up here
                if y.Name == v.Name then
                    y.Amount.Value = y.Amount.Value +v.Amount.Value
                else
                    local x = v:clone()
                    x.parent = plr.Inventory

            break
        end
            end
        end
        end





end)
0
if the table is empty it will return {} Puppynniko 1059 — 1y

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
1 year ago

your supposed to do plr.Inventory:GetChildren() from what i can see

Ad

Answer this question