Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get Value from table?

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

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)

3 comments

0

ok thank you ill do that

0

It didn't fix it, its having an error: Attempt to index nil with 'Price'

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.