Trello Ban Whitelist script bans whitelisted players. need help fixing

local API = require(script.Parent:WaitForChild("TrelloAPI"))
local WhitelistBoardID = API:GetBoardID("Roblox1R4Whitelist")
local WhitelistID = API:GetListID("Whitelisted",WhitelistBoardID)







local function CheckPlayerWhitelisted(Player)
	local IsWhiteListed = false
	local WhitelistCards = API:GetCardsInList(WhitelistID)
	
	for _, Card in pairs(WhitelistCards) do
		
		if string.find(Card.Name, Player.UserId) then
			IsWhiteListed = true
		else
			IsWhiteListed = false
		end
	end
	
	
	return IsWhiteListed
end


local function BanUnwhitelisted()
	while true do
		task.wait(5)
		local Players = game.Players:GetChildren()
		
		for _, Player in pairs(Players) do
			local IsWhitelisted = CheckPlayerWhitelisted(Player)
			if IsWhitelisted == false then
	
				Player:Kick("You are not whitelisted. Contact the owner to be whitelisted.")
			else
				print("Player is whitelisted")
			end
		end
	end
end

local BanUnwhitelistedCoroutine = coroutine.create(BanUnwhitelisted)
coroutine.resume(BanUnwhitelistedCoroutine)

game.Players.PlayerAdded:Connect(function(Player)
	print("Player joined")
	local IsWhitelisted = CheckPlayerWhitelisted(Player)
	if IsWhitelisted == false then
		
		Player:Kick("You are not whitelisted. Contact the owner to be whitelisted.")
	else
		print("Player is whitelisted")
	end
end)

Problem with code: the Card returns nil and so it bans players even if a card with their userid is in a list, also I enabled http requests and also set the right token and key on the Trello module(Trello API [Original] - Roblox).
I checked if the name of the board was correct and also if it was private.(its in workspace visible mode)

Try making a similar script with the same setup that reads a card and prints it to output. This will help you diagnose if it’s an issue with your trello board or your whitelist script.

Looking back at your code it seems like your for loop might be the issue. Instead of setting a variable and then returning that variable, try simply returning true or false. This should also break the loop. For example:

	for _, Card in pairs(WhitelistCards) do
		
		if string.find(Card.Name, Player.UserId) then
			return true
		else
			-- do nothing
		end
	end

Think of it this way:
The player’s user id is the first card in a list of four. They should be able to join because their user id exists on the list. Your loop doesn’t stop when someone is found to be whitelisted, so it runs again for the next card. This next card doesn’t match the player’s user id, so it returns false even though they are whitelisted. Your function will return nothing at all if they aren’t whitelisted, so make sure to account for that.