How can I change a variable for multiple scripts at same using a module?

I’m trying to get a module to go off and change the variable for multiple scripts for a touch event.
Currently, I’m only using the module with one other script. When I touch the object for the touch event I get "Infinite yield possible on "ServerScriptService:WaitForChild(“GameModule”)

Current Module

local GameModule = {}
local GAME_ACTIVE = false
local GAME_START = game.Workspace.GameStart

GAME_START.Touched:Connect(function()
	GAME_ACTIVE = true
end)

GameModule.StartGame = function ()
	if GAME_ACTIVE == true then
		wait(30)
		return GAME_ACTIVE
	elseif GAME_ACTIVE == false then
		return GAME_ACTIVE
			
	end	
	
end

return GameModule

Current script using it (Not full script, can add more if needed) This script is in a meshpart.

local BlockWait = 0
local GameModule = require(game.ServerScriptService:WaitForChild("GameModule"))
local GAME_ACTIVE = GameModule.DropLayers()


while GAME_ACTIVE == true do
	FallEvent = math.random(0,1)
	RiseEvent = math.random(0,4)
	BlockWait = math.random(0,10)
	if FallEvent == 0 then
		wait(BlockWait)
		model.BrickColor = BrickColor.new("Crimson")

The infinite yield message implies that the script cannot find a child called “GameModule.” Is the module parented to ServerScriptService and named “GameModule”

1 Like

Oh! The file name has to also be changed as well, makes sense.

Alright, now I have no errors. However, I tried using a print statement to see if the module would work when I touched the part or the variable (GAME_START). And I get nothing.

You’d need to make GAME_START an element in the module, so you’d do this;

local GameModule = {}
local GAME_ACTIVE = false
GameModule.GAME_START = game.Workspace.GameStart

GameModule.GAME_START.Touched:Connect(function()
	GAME_ACTIVE = true
end)

GameModule.StartGame = function ()
	if GAME_ACTIVE == true then
		wait(30)
		return GAME_ACTIVE
	elseif GAME_ACTIVE == false then
		return GAME_ACTIVE
			
	end	
	
end

return GameModule
1 Like

Awesome got it to work, I added the touch event in the script outside of the GameModule and that got it to return true.

1 Like