What do i do for these types of things

```lua
local prices = {
	"Chitatap" == 10,
}

BuyItem.OnServerEvent:Connect(function(player,item)
	local price = prices[item]
	print(price,item)

whats the best way to get the value from the table?

1 Like
local Prices = { -- Create a dictionary
	Chitatap = 10;
	Poop = 2;
};

-- Example 1
print(Prices.Poop); -- output is 2
print(Prices.Chitatap); -- output is 10

-- Example 2
function PrintItem(ItemName)
	if Prices[ItemName] then -- Check if item exist
		print(ItemName, Prices[ItemName]);
	end;
end;

PrintItem("Poop") -- Fire
2 Likes

why is there error

1 Like

Could you send the full script with the line that’s erroring?

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local BuyItem = ReplicatedStorage.RemoteEvents.BuyItem
local SellItem = ReplicatedStorage.RemoteEvents.SellItem
local Tools = ServerStorage.Tools:GetDescendants()
local CheckMoney = require(ReplicatedStorage.ModuleScripts.CheckMoney)

local prices = {
	"Chitatap" == 10,
}

BuyItem.OnServerEvent:Connect(function(player,item)
	local price = prices[item.Name]
	print(price,item.Name)
	
	for i,tool in pairs(Tools) do
		if tool:IsA("Tool") then
			if tool.Name == item then		
				if CheckMoney.Function(player,price) then
					local money = player.NonPvPStats.Money
					
					money.Value -= price
					tool:Clone().Parent = player.Backpack

				end
			end
		end
	end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BuyItem = ReplicatedStorage.RemoteEvents.BuyItem

for i,v in pairs(game.workspace.Buttons.BuyItems:GetDescendants()) do
	if v:IsA("ClickDetector") then
		local tool = v.Parent
		
		v.MouseClick:Connect(function(player)
			BuyItem:FireServer(tool)
		end)
	end
end

image

1 Like

What’s in your CheckMoney module? The error occurs when you require it on line 6.

i dont think this the problem but here it is

local module = {}

function module.Function (player,goal)
	local money = player.NonPvPStats.Money
	
	if money.Value >= goal then
		return true
	end
end

return module
1 Like

You need to remove the extra equals sign because what this code does right now is check if that string is equal to 10, which is false, so what you’re really left with is:

local prices = {
	false
}

When you try to index prices[item.Name] you get nil because Chitatap doesn’t actually exist in prices, explaining why line 14 prints nil Chitatap. Since now price == nil, CheckMoney.Function(player,price) will error on line 6 because the goal parameter is nil.

What you want to type is this:

local prices = {
	Chitatap = 10
}

tanks


local prices = {
	["Chitatap"] = 10,
	["Coffee"] = 3,
	["Milk"] = 3,
	["Water"] = 2,
}

BuyItem.OnServerEvent:Connect(function(player,item)
	local Money = player.NonPvPStats.Money
	local price = prices[item.Name]

	for i,tool in pairs(Tools) do
		if tool:IsA("Tool") then
			if tool.Name == item.Name then		
				if Money.Value >= price then
					
					Money.Value -= price
					tool:Clone().Parent = player.Backpack

				end
			end
		end
	end
end)
1 Like