PlayerJoined event not firing

Alright, so I’m trying to make a Trello board blacklist, however, my PlayerAdded event isn’t firing. I have a print statement in it because I was debugging it but nothing. Everything else works outside of the function, the function just won’t fire from the event.

Here is my script: (It is in ServerScriptService)

local TrelloAPI = require(script.TrelloAPI) -- Get the Trello API

local BoardID = TrelloAPI:GetBoardID("Blacklist Test") -- Get's the Id of my Trello Board
local ListID = TrelloAPI:GetListID("Blacklisted Users",BoardID) - Finds the Id of the list of blacklisted userIds
local blacklisted = TrelloAPI:GetCardsInList(ListID) -- get's all userId's from that list as a table

function checkBanned(userId) -- Name of the function is pretty straight forward
	local isBanned = false

	for _, v in pairs(blacklisted) do -- check's all cards to see if any match the userId
		
		if v.name == userId then
			isBanned = true
		end
	end

	return isBanned
end

game.Players.PlayerAdded:connect(function(player) -- here is where my problem lies. I can get the API working seperately but I can't get the event to fire
	
	print("Player joined") -- won't print when I join
	
	if checkBanned(player.UserId) == true then
		player:Kick("You are blacklisted.")
	end
end)

If you need anymore info just shoot me a question.

The event just still straight up doesn’t fire at all. Like nothing, not even a error

Defining local functions inside of other functions are bad practice. Try putting more print statements between lines to see where your code stops working. This will make it easier to pinpoint where it went wrong.

local TrelloAPI = require(script.TrelloAPI) -- Get the Trello API

local BoardID = TrelloAPI:GetBoardID("Blacklist Test") -- Get's the Id of my Trello Board
local ListID = TrelloAPI:GetListID("Blacklisted Users",BoardID) - Finds the Id of the list of blacklisted userIds
local blacklisted = TrelloAPI:GetCardsInList(ListID) -- get's all userId's from that list as a table
print("Variables initialized");

function checkBanned(userId) -- Name of the function is pretty straight forward
	local isBanned = false

	for _, v in pairs(blacklisted) do -- check's all cards to see if any match the userId
		
		if v.name == userId then
			isBanned = true
		end
	end

	return isBanned
end
print("checkBanned function initialized");

game.Players.PlayerAdded:Connect(function(player) -- here is where my problem lies. I can get the API working seperately but I can't get the event to fire
	
	print("Player joined") -- won't print when I join
	
	if checkBanned(player.UserId) == true then
		player:Kick("You are blacklisted.")
	end
end)
print("PlayerAdded connection registered")

I’ve tried moving the function around and adding a print statement at essentially every step but the only thing that isn’t working is anything that goes within the PlayerAdded event

I’ve noticed that one of your notes in the original post isn’t a note, and is raw text.

local ListID = TrelloAPI:GetListID("Blacklisted Users",BoardID) - Finds the Id of the list of blacklisted userIds

I added those notes in on here they aren’t in my actual script

Maybe it’s stuck there, try to add a print(“Hello World”) just before the

If it doesnt print then you might want to see whats wrong in the upper section

There’s a possibility that whatever is going on in the require() is taking too much time to complete, and concurrently during that time you are joining the game. Therefore, by the time you connect to the player added event, you’ve already joined the game and thus wont fire it.

This is a pretty common problem when using :WaitForChild(). I don’t know what is happening internally with your trello module, so I can’t say for certain. If you’ve already ruled out that is is not hanging the script, then a simple workaround, is connecting your player added event to a defined function, and then iterating over all players in the game and also calling that same function.

As an example:

local function onPlayerJoin(Player)
    print("Player Joined", Player)
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
for _,Player in pairs(game.Players:GetPlayers()) do
    task.spawn(onPlayerJoin, Player)
end
1 Like

I test out your code and the only issue I found so far is you need to check your module script as well as you didn’t comment your code correctly you only added 1 dash instead of 2 which causes your code to error at the top on line 4

local ListID = TrelloAPI:GetListID("Blacklisted Users",BoardID) - Finds the Id of the list of blacklisted userIds```