Can't access a table in the module script from another script

Good morning everyone,

I’m experimenting with Module Script.

When I tried accessing a table I put inside the module it gives me nil as if the table doesn’t exist

here is my Module script:

local MouseInfo = {}

Info = {
	
	["Curse"] = {
		["Price"] = 25,
		["Rarity"] = "Common",
		
		["Death"] = {
			["Price"] = 50,
			["Rarity"] = "Uncommon"
		}	
	}
}

return MouseInfo

and here is where I access it:

event.OnServerEvent:Connect(function(player, Mouse)
	local Type = Mouses.Info[Mouse]

Am I doing something wrong?

Thank you

Try changing Info to MouseInfo.Info

What is Mouses?
Is that the variable that you require the module?
For example:

local Mouses = require(modulescript)

Here is my full script:


local Mouses = require(script.MousePrices)
local event = game:GetService("ReplicatedStorage"):FindFirstChild("BuyingEvent")


event.OnServerEvent:Connect(function(player, Mouse)
	local Type = Mouses.MouseInfo.Info[Mouse]
	print(Type)
	print(Type["Price"])
	if player.leaderstats.Clicks then
	
		print(1)
	end
	    event:FireClient(player, true)
		event:FireClient(player, false)
end)


Don’t mind the lower part It’s work in progress

“Info” Is still nil for some reason

Ah, now you’ll have swap this line

local Type = Mouses.MouseInfo.Info[Mouse]

With this line

local Type = Mouses.Info[Mouse]

I guess your thought process is that you’re requiring the script in which you store the MouseInfo object, but, in reality, ModuleScripts work in a way that you actually require the object you return at the last line of the ModuleScript, which in your case is the MouseInfo object, so your Mouses variable is already pointing at it.

Change your module to this:

local MouseInfo = {}

MouseInfo.Info = {

	["Curse"] = {
		["Price"] = 25,
		["Rarity"] = "Common",

		["Death"] = {
			["Price"] = 50,
			["Rarity"] = "Uncommon"
		}	
	}
}

return MouseInfo

Then use it as:

local Type = Mouses.Info[Mouse]

Oh it seems I forgot to put the name of the Module Script local before my variable. Thank you :smiley: