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

Inventory Store Error (Attempt to get length of upvalue) Whats Wrong?

Asked by 6 years ago
Edited 6 years ago

13:05:55.555 - ServerScriptService.Inventory:15: attempt to get length of upvalue 'inv' (a userdata value) 13:05:55.556 - Stack Begin 13:05:55.557 - Script 'ServerScriptService.Inventory', Line 15 13:05:55.558 - Stack End

Output ^^^^

local inv = game:GetService("DataStoreService"):GetDataStore('InventoryMetricDevGalacticzy')

game.Players.PlayerAdded:Connect(function(plr)
    local inventory = Instance.new("Folder",plr)
    inventory.Name = 'Inventory'
    local items = inv:GetAsync(plr.UserId) or {}
    for i,v in pairs(items) do
        if game.ReplicatedStorage.ItemValues:FindFirstChild(v) ~= nil then
            game.ReplicatedStorage.ItemValues[v]:Clone().Parent = inventory
        end
    end
    inventory.ChildAdded:connect(function(c)
        inv[#inv+1] = c.Name -- error here
        inv:SetAsync(plr.UserId, inv)
    end)
    inventory.ChildRemoved:connect(function(c)
        local items = {}
        for i,v in pairs(inventory:GetChildren()) do
            items[i] = v.Name
        end
        inv:SetAsync(plr.UserId, items)
    end)
end)

Script^^^

Please help it is for my game I just need a quick fix and that is all thanks :D

1 answer

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

Line 13 of this extract:

inv[#inv+1] = c.Name

You're calling the length operator on a datastore, which you can't do

I'm guessing what you meant to do was:

items[#items+1] = c.Name
inv:SetAsync(plr.UserId, items)
0
I did that, no errors but it doesnt go back to my inv MetricDeveloper 0 — 6y
0
never mind messed up again MetricDeveloper 0 — 6y
Ad

Answer this question