Dictionary functions in module returns nothing

I don’t know how to define this but dictionary functions or whatever they’re called that are returned by a module seem to return nothing. It also seems to return a nil value error.
I am doing this for a shop rework and I don’t wanna use this method inside a normal script.

local ShopFunctions = {
	["Sword"] = function(D)
		print(D)
		return 0
	end,
}

Actual error here

return {
	["Sword"] = function(Player)
		return 0
	end,
}

What is the script where you are calling these functions?

> print(require(game:GetService("ServerScriptService").Modules.Engine.ModuleScript)["Sword"]())  -  
Studio  print(require(game:GetService("ServerScriptService").Modules.Engine.ModuleScript)["Sword"]()):1: attempt to call a nil value  - 
1 Like

Remember that the require() is the one that would return the dictionary. You were treating the modulescript as if it was a dictionary, hence why it doesn’t work. The indexing part should be after the require() line.

So it should be done like this instead:

print(require(game:GetService("ServerScriptService").Modules.Engine.ModuleScript)["Sword"]())