Why is this not recognizing the Module Value?


  1. I’m trying to make a player check system that will, if we have a certain amount of players… it will start the game.

  2. The issue is that when I try to use the CoreModule to get the value, it won’t recognize the value

  3. I’ve tried using a string and the code string.unpack() but that failed.


Error Script

local currentlyinrace = game.Workspace.GameTimer.currentlyinrace.Value
local CoreModule = require(script.Parent.CoreModule)
local gameFixed = false
local gamePlaying = false 
local num = 0

while true do
	wait(5)
	print(CoreModule.CoreData.PlayersNeeded) -- This comes back with the value, 2.
	if game.Players.NumPlayers >= CoreModule.CoreData.PlayersNeeded and game.Workspace.GameTimer.currentlyinrace.Value == false then
		if gamePlaying == false then
			gamePlaying = true
			gameFixed = false
			game.Workspace.GameTimer.currentlyinrace.Value = true
			CoreModule.CoreData.Status.Value = "Intermission..."
			CoreModule.FindFunction("Intermission")
			wait(2)
		end
	elseif game.Players.NumPlayers < CoreModule.CoreData.PlayersNeeded and game.Workspace.GameTimer.currentlyinrace.Value == true then
		game.Workspace.GameTimer.currentlyinrace.Value = false
		CoreModule.CoreData.Status.Value = "2 players required to start game!"
		if gamePlaying == true then
			gamePlaying = false
			if gameFixed == false then
				gameFixed = true
				CoreModule.FindFunction("Reset")
			end
		end
		wait(2)
	else
		print("Check Completed")
		CoreModule.CoreData.Status.Value = "First Check is not running correctly."
	end
end

Core

--/Made By MillerrIAm\--
--/Services\--
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--/Core\--
Core = {
    CoreData = {
        Status = ReplicatedStorage:WaitForChild('StatusValue'),
        Admins = {678299,571909198,489143945},
        InRace = {},
        AFK = {},
        Winner = false,
        Tie = false,
        num = 1,
        PlayersNeeded = 2,
    }
}
return Core

Thank you for any help you can give me.

1 Like

Bumping this so I can hopefully get help…

1 Like

Could you clarify which value that you are trying to retrieve from the ModuleScript is not being recognized/is causing an error?

1 Like

CoreModule must be a ModuleScript, and you’re not returning it, you need to do that in order to access it.

Add a return ModuleScript at the end of your core module script.

2 Likes

I fixed the Original Post, I have a return Core at the bottom of my module.

Current Module;

--/Made By MillerrIAm\--
--/Services\--
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--/Core\--
Core = {
    CoreData = {
        Status = ReplicatedStorage:WaitForChild('StatusValue'),
        Admins = {678299,571909198,489143945},
        InRace = {},
        AFK = {},
        Winner = false,
        Tie = false,
        num = 1,
        PlayersNeeded = 2,
    }
}

return Core

Current Server Script

local currentlyinrace = game.Workspace.GameTimer.currentlyinrace.Value
local CoreModule = require(script.Parent.CoreModule)
local PlayerLimit = CoreModule.CoreData.PlayersNeeded --Causing the error
local gameFixed = false
local gamePlaying = false 
local num = 0

while true do
	wait(5)
	print(CoreModule.CoreData.PlayersNeeded)
	if game.Players.NumPlayers >= PlayerLimit and game.Workspace.GameTimer.currentlyinrace.Value == false then --Error Line
		if gamePlaying == false then
			gamePlaying = true
			gameFixed = false
			game.Workspace.GameTimer.currentlyinrace.Value = true
			CoreModule.CoreData.Status.Value = "Intermission..."
			CoreModule.FindFunction("Intermission")
			wait(2)
		end
	elseif game.Players.NumPlayers < PlayerLimit and game.Workspace.GameTimer.currentlyinrace.Value == true then -- Error Line
		game.Workspace.GameTimer.currentlyinrace.Value = false
		CoreModule.CoreData.Status.Value = "2 players required to start game!"
		if gamePlaying == true then
			gamePlaying = false
			if gameFixed == false then
				gameFixed = true
				CoreModule.FindFunction("Reset")
			end
		end
		wait(2)
	else
		print("Check Completed")
		CoreModule.CoreData.Status.Value = "First Check is not running correctly."
	end
end

I tried putting a .Value at the end of my PlayerLimit Variable but it just gave me the error of attempt to index number with 'Value'.

@DecodedString @StrongBigeMan9

1 Like

That error that you described is occurring because the “PlayerLimit” variable is not referring to an Instance that has a “Value” property. Since the variable is equal to a number, you wouldn’t need to index Value because you’re already retrieving the value by referencing the variable.

However, I just noticed that you’re comparing that number to game.Players.NumPlayers – what is this value? If you’re trying to determine how many players are in the game, you can call :GetPlayers() on the player’s service and use the length operator:

local Players = game:GetService("Players")
local currentPlayerCount = #Players:GetPlayers() -- This will be a number that indicates how many players are in the game

if currentPlayerCount >= PlayerLimit and ... then
    -- Continue
elseif currentPlayerCount < PlayerLimit and ... then
    -- Continue
end
1 Like

So then, what do you believe is causing my issue? I genuinely don’t see an issue with my code how it is..


To answer your question, I will refer to the Developer Forum to get my source;
The property: numPlayers is a deprecated feature for the Players Instance, it returns the number of people in the server at the current time, so basically… the equivilant to the #Players:GetPlayers() variable. image

Does anything else appear in the Output during runtime? Utilizing the code you’ve provided here (with a few modifications based on context), I’ll provide a test place where I was able to get it to work:


Test Place & Results

Module Test Place.rbxl (23.8 KB)

Take note that certain aspects of the test place may not line up accurately with what you have in your game, such as the usage of CoreModule.FindFunction(), since that function wasn’t displayed in the ModuleScript even though it was referenced from the Server Script code that was provided.

After making some modifications, I first tested it with one player to see what would display in the Output. In this case, it printed the following:

2 -- Line 21 (Number of players required)
"Check Completed" -- Line 62
"1 player(s) is/are currently in the game" -- Line 63

This demonstrated that the conditional statements for the PlayerLimit & CurrentlyInRace value were not met, which was still a good sign because it didn’t error.


Afterward, I went to the “Test” tab and started a local test with 2 players and it only printed the number of players required (line 21) and then the part in the Workspace changed colors which indicated that the first conditional statement was met because on line 34 is where the color of the “GameTimer” was adjusted.

I then disconnected one of the clients so that only one player would remain, and the following printed in the Output:

2 -- Line 21 (Number of players required)
"Check Completed" -- Line 62
"1 player(s) is/are currently in the game" -- Line 63

This demonstrates that the script went back to printing everything inside of the “else” statement as the other conditions were not met. No errors occurred during this process.

Unless some of the code was omitted from the original post, such as what CoreModule.FindFunction() is referring to (since I don’t see that anywhere in the codeblock from the ModuleScript), I can’t be certain about what else could be causing it to work improperly.


Thanks for letting me know about that since I was unaware it was a property – however, even if that didn’t end up being the source of the error, since it is deprecated, that means it is not advised to be used in new work. It mentions on the page that using :GetPlayers() is recommended to be used instead, so I’d suggest swapping that over.

1 Like