Module script using values created in other function

I have a module script with all the gamemodes in it, my problem is that whenever I call I value from this script to my main one, It doesn’t know it.

Main Script

gamemodes.Flood()

Module Script

local gamemodes = {
	Flood = function()
		while wait() do
			local Up = 290
			wait()
			repeat 
				ChosenMap.Water.CFrame = ChosenMap.Water.CFrame + Vector3.new(0, 0.05, 0)
				wait(0.08)
				Up = Up - 1
			until #playersInRound == 0 or Up <= 0 or game.ReplicatedStorage.InRound.Value == false
			if #playersInRound == 0 then
				break
			end
			wait(4)
			repeat 
				ChosenMap.Water.CFrame = ChosenMap.Water.CFrame + Vector3.new(0, -0.05, 0)
				wait(0.01)
			until #playersInRound == 0 or game.ReplicatedStorage.InRound.Value == false
			break
		end
	end
}
return gamemodes

My problem here is that the module script can’t find players in round. In the main script the players in round is created. It also can’t get the chosen map because it is random. Someone please help me find a fix to this. I am lost…

You can pass the players as an arg when calling gamemodes.Flood(plrs) and access them in the module script.

If the main script is a module, you can pass the keyword self and your second script will be able to modify values in the main script.

Please expand on what you are saying because I don’t understand very well.

-- Main Script
gamemodes.Flood(plrs)

-- ModuleScript
local gamemodes = {}

function gamemodes.Flood(plrs)

end

return gamemodes

See how I am passing “plrs” to the module script? You can do that with all the values.