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

How do I get Value from table?

Asked by 3 years ago

I have a inventory system which has a gui, so when you kill a item it goes into a table and is displayed on the gui.

I want to Make a shop in which will sell all items in the players inventory folder and then clear it.

Here is the shop gui script

script.Parent.MouseButton1Click:Connect(function()

    local ReplicatedStorage = game:GetService("ReplicatedStorage")

    ReplicatedStorage.Remotes.Sell:FireServer()

end)

Here is the what gets loaded on to the table when there needed.

local ItemsInfo = {
    ["item1"] = {
    Price = 200;
    };

    ["item2"] = {
        Price = 10;
    };
return ItemsInfo

Table is in sever scrips

local Inventory = {     }

Here is the main problem

RepStorage.Remotes.Sell.OnServerEvent:Connect(function(item, player)

    local itemInfo = ItemsInfo[item]

    local Sum = itemInfo.Price
    Sum = 0 
    for i,v in pairs(itemInfo) do
        Sum = Sum + v

    end
    if Sum > 0 then

        local player = game.Players.LocalPlayer
        player.leaderstats.Teccers.Value = player.leaderstats.Teccers.Value + Sum


    end
end)


Please try and help, Or at least give something

1 answer

Log in to vote
0
Answered by
BiIinear 104
3 years ago

The problem is on the first line. When doing .OnServerEvent, the first parameter is always going to be player.

So, switch the parameters around by doing (player, item)

0
ok thank you ill do that Boss246813579 -6 — 3y
0
It didn't fix it, its having an error: Attempt to index nil with 'Price' Boss246813579 -6 — 3y
0
I saw this coming. In the first code block on line 5, you didn't send over the item in parameters. In other words, the parameters are empty. BiIinear 104 — 3y
Ad

Answer this question