Problems with chatted and matching strings

When I just did game.Players.LocalPlayer.Chatted it worked fine but now that I added it into a function it just doesn’t work.

It returns that the player is valid but it wont print got past!!!

function SplitMessageParts(SplitType,Message,ReturnPart)
	if SplitType == "Space" then
		local Split = Message:split(" ")
		return Split[ReturnPart]
	else
		--
	end
end

wait(game:IsLoaded())
wait(3)

function IsAPlayer(Name)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name == Name then
			print("Name found!!! returning")
			return Name
		else
			print("N ame wasnt found in IsAPlayer Lol")
			return false
		end
	end
end

function Chatted(Requirements,Type)
	if Type == "ReturnPlayer" then 
		game.Players.LocalPlayer.Chatted:Connect(function(Message)
			print("Chatted xD")
			if Chatted(SplitMessageParts("Space",Message,1) == Requirements[1] and SplitMessageParts("Space",Message,2) == Requirements[2] and SplitMessageParts("Space",Message,3) == IsAPlayer(SplitMessageParts("Space",Message,3))) then
				print("got past!!!")
				return Message
			end
		end)
	elseif Type == "Normal" then
		
	end
end

You have to run the code container any RBXScriptConnection is in, otherwise it will not connect.

Example:

local function MyNewFunction(args)
    game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
        print("My New Function works!")
    end)
end
-- This script wont print anything when the player chats unless you call 'MyNewFunction' first.