Calling value from module script

I am trying to get a value from module script. But I only have the name of this value. how can i call that value?

code that calls this value:

local function calculateAreaStats(player: Player)
	local stat = 0 
	for i,v in pairs(player.areas:GetDescendants()) do
		if v.Value == true  then
			local areaStat = AreasConfig[v]
			print(areaStat)
			stat += areaStat
		end
	end
	return stat
end

and module script:

local module = {
	Area1 = 4,
	Area2 = 5,
}

return module

One of the most Basic thing’s you can do with a ModuleScript, Use require() to access the ModuleScript

local Module = require(Module) -- Withinrequire, path your ModuleScript
print(Module.Area1)

i already did that. my question is how can i call v value from module script named AreasConfig?

This is still a very simple thing

for i,v in Module do

or

for i,v in Module.Table do -- if you have another table

i is the name of the value (the key)
v is the value itself

1 Like

Thanks it worked but the module called every value in the script this time too

local function calculateAreaStats(player: Player)
	local stat = 0 
	for i ,v in pairs(player.areas:GetDescendants()) do
		if v.Value == true  then
			--print(v)
			for v,g in AreasConfig do
				local areaStat = g
				print(areaStat)
				stat += areaStat
			end
		end
	end
	return stat
end```

  17:49:20.695  4  -  Server - Stats:55
  17:49:20.695  5  -  Server - Stats:55
local function calculateAreaStats(player: Player)
	local stat = 0 
	for i,v in pairs(player.areas:GetDescendants()) do
		if v.Value == true  then
			local areaStat = AreasConfig[v.Name] -- change this from v to v.Name  or v.Value
			print(areaStat)
			stat += areaStat
		end
	end
	return stat
end
1 Like

Thanks i understand my mistake

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.