Nil value with item in module script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I have a shopgui and when a player buys an item I want to find the amount of money is required to buy it by checking how much it’s worth in a module script.

  1. What is the issue? Include screenshots / videos if possible!
    This is the localscript:
local module = require(script.Parent.ItemCost)

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.SelectedGear.Value ~= "" then
		local cost = module[table.find(module, script.Parent.SelectedGear.Value)]
		print(cost)
	end
end)

module script:

local cost = {
	["Sword"] = 150;
	["LaserGun"] = 500;
	["Jump"] = 750;
	["2xSpeed"] = 1000
}

return cost

It prints out nil tho in the localscript.
Is there any other way of finding something in a module script?

I can’t really find anything about this. :confused:

I have done this before but that was a long time ago so this might be wrong. If it is I can go back to my old game and find how to do it. But I believe you could do something like this:

local module = require(script.Parent.ItemCost)

local currentWeapon = --this is the frame for the weapon they want to buy, for example the "Sword"
script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.SelectedGear.Value ~= "" then
		local cost = module[currentWeapon] --If currentWeapon was set to "Sword" then it should return 150
	end
end)
1 Like