ModuleScript + PlayerAdded event == Not working?

So I’m currently attempting to make a ModerationSuite however when trying to add a player added event into the module script, it doesn’t work too well. Any thoughts or help is welcome. Nothing is printed in the besides the things before the PlayerAdded event.

print('cWarn / Fetching moderators')
local Moderators = Config["Moderators"]
game.Players.PlayerAdded:Connect(function(Player)
	if Moderators[Player.Name] or Moderators[Player.UserId] then
			print(Player.Name .. " / Passed Moderator Authorization")
			Player.Chatted:Connect(function(Message)
						cWarn.CommandCheck(Message,Player)
			end)
	else
		print(Player.Name .. " / Failed Moderator Authorization")
	end
end)

–This is just a code snippet, don’t mind the extra “end)”

1 Like

You would have to require the module for it to work

1 Like

Can you describe what you mean by “it doesn’t work too well?” The code snippet you provided looks logically sound, however there’s quite a few unknown variables.

  1. Is something wrong about the way the Config[“Moderators”] table is setup?
  2. Does the function cWarn.CommandCheck work correctly?
  3. Does the code that loads your module work correctly? As @theking48989987 said, did you remember to put a require in?
1 Like

The module is required, its been from the start.

The config works sound as it can be, it’s essentially a table with all the config and their values, Yes, the function works fine, I tested it before, and yes the module loads.

What I mean by it doesn’t “work too well”, I mean it works up until the PlayerAdded event, then the script just…stops.

I’m not sure what it is but I’d suggest going through it with the debugger. That should give you more of an idea of where it’s stopping

1 Like

Put the PlayerAdded event in your Script and require it inside playeradded and then config

1 Like

I’m not trying to go for the effect where every time a player is added it reloads the main module…

I believe what he is trying to say is this:

local moderatorModule = require(game.ReplicatedStorage.Module)

game.Players.PlayerAdded:Connect(function(Player)
	if moderatorModule["Moderators"][Player.Name] or moderatorModule["Moderators"][Player.UserId] then
		print(Player.Name .. " / Passed Moderator Authorization")
		Player.Chatted:Connect(function(Message)
			cWarn.CommandCheck(Message,Player)
		end)
	else
		print(Player.Name .. " / Failed Moderator Authorization")
	end
end)

Not sure if this will make any change though.

2 Likes

Require it outside of the event, sorry.

I’m aware of where it stops, I’ve added simple print debugs to find the exact spot and its the PlayerAdded event call. (game.Players.PlayerAdded:Connect(function(player))

I’m currently trying hold all but the configuration inside the module script, this project is going to be closed source.

You have to make Module scripts public now if you want other players using your system.

1 Like

Actually, I know of a service that uses HTTP Requests to pull closed source code from an external host.

Pass what you need into the initiation of your module in the pa event.

local module = require(module)

game.Players.PlayerAdded:Connect(function(args)
   module:init(config)
end)
1 Like

Yeah using HTTP Service is most likely a work around to this but no one has it enabled by default which may create difficulty if you’re wanting to make the system available for everyone to use.

He could make another module to require a new module with the main http code so they do not have to write it themselves?

Since I don’t see a solution to the question yet, I figure I’ll pitch in.

There’s a chance that the PlayerAdded event is connected after players have already joined. Since that can be the case, you need to loop through current players and check them right after connecting the event:

print('cWarn / Fetching moderators')
local Players = game:GetService("Players")
local Moderators = Config["Moderators"]

function onPlayerAdded(Player)
	if Moderators[Player.Name] or Moderators[Player.UserId] then
		print(Player.Name .. " / Passed Moderator Authorization")
		Player.Chatted:Connect(function(Message)
			cWarn.CommandCheck(Message,Player)
		end)
	else
		print(Player.Name .. " / Failed Moderator Authorization")
	end
end)

Players.PlayerAdded:Connect(onPlayerAdded)

for _,Player in pairs(Players:GetPlayers()) do
	onPlayerAdded(Player)
end
1 Like

Attempted this solution, resulted in the same outcome.

I’ll try this, however this would be odd behavior for the event as it’s worked correctly in the past for previous scripts that attempted to use the .PlayerAdded event and than check the player for something.