Global Variables on modules

Do globals work in modulescripts or not? Since for some reason it’s nil.

--Server
_G.CattoShop = workspace.Map.yeah.DJJD
--Module, Required by a server script that gets destroyed eventually.
local module =  {
	["Normal Bat"] = function(Player:Player?)
		if Prices.NormalBat <= Player.leaderstats.TIX.Value and Ristal:Distance(Player.Character, 10, _G.CattoShop) then
			return true
		end
	end,
}
--Script that requires the module(It's placed in ServerScriptService)
require(script.Parent)
script:Destroy()
5 Likes

Actually I think globals broke as a whole, why??

function _G:ReP(d,t)
	if t:lower():match("ev") then
		return d.EventsFolder
	end
	if t:lower():match("va") then
		return d.ValuesFolder
	end
end
1 Like

Your script likely fell victim to race conditions: The script is trying to execute the function/access the index before the global is defined.

I don’t recommend using _G, as ModuleScripts were created to serve its purpose, but better.

1 Like

I know, but my entire game relies on globlals (especially the ReP function) and requiring scripts comes down with performance.

3 Likes

requiring modules shouldn’t hinder performance at all unless you’re requiring like 100 times/frame?

Your game relying on globals is also a sign of bad game architecture, modules can achieve the same thing and prevent race conditions

3 Likes