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)”
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.
Is something wrong about the way the Config[“Moderators”] table is setup?
Does the function cWarn.CommandCheck work correctly?
Does the code that loads your module work correctly? As @theking48989987 said, did you remember to put a require in?
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.
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)
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))
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.
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
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.