How to simply call a Variable from a Module Script?

The title is pretty self explanatory

I just want to know how to retrieve a Variable from a Module script.

Module Script:

local GCM = {}

-- GAME CORE [SHORTCUT] --

GameInfoFolder = GameCore.GameInfo

ScriptsFolder = GameCore.Scripts

PlayerParentFolder = GameCore.PlayerParent

CurrentMapFolder = GameCore.CurrentMap

LobbyFolder = GameCore.Lobby

RedOrbsFolder = GameCore.RedOrbs

-------------------------------------------

-- GAME CORE [PlayerParent] --

InLobby = PlayerParentFolder.InLobby

OutsideLobby= PlayerParentFolder.OutsideLobby

-------------------------------------------

-- GAME CORE [SCRIPT VALUES] --

chosenMap = GameInfoFolder["Chosen Map"]

mapID = chosenMap.MapID

playerQuantity = GameInfoFolder.PlayerQuantity

startingGame = GameInfoFolder.StartingGame

Stat = GameInfoFolder.Stat

matchResults = GameInfoFolder.MatchResults

remainingTime = GameInfoFolder.RemainingTime

startlineTime = GameInfoFolder.RemainingTime.StartlineTime

matchresultsTime = GameInfoFolder.RemainingTime.MatchResultsTime

NoMorePlayers = GameInfoFolder.NoMorePlayers

-------------------------------------------

return GCM

What i am trying to do is Retrieve the startlineTime variable in this piece of code:

local STARTLINE_TIME = GCM.startlineTime.Value -- HOW LONG THE COUNTDOWN TO START THE RACE LASTS

But it keeps returning nil whenever i start the game:

image

My question is simple, how to call variables from module scripts?

2 Likes

You need to set the variable you want to reference, to be part of the module, using the . method.

For example:

--ModuleScript
local module = {}

module.variable = "heyyyyy"

return module
--Normal Script
module = require( module location )

print(module.variable)

This would print “heyyyyy” when you run the Normal Script.

Or, in your case:

--ModuleScript
GCM.startlineTime = GameInfoFolder.RemainingTime.StartlineTime
--Normal Script
local STARTLINE_TIME = GCM.startlineTime.Value
7 Likes

Lol i forgot to do that, sometimes i get so overwhelmed with errors that my brain stops working, sorry to take your time to answer a dumb question xD

Just make sure to keep in mind modulescript results are cached, so if you change the variable after requiring the module for the first time it won’t be up to date anymore.