How do I fix this script text filter?

I made a script that is supposed to make a command that can be used to warn players if they do something. (!Warn PlayerName Reason). The filter on it isn’t working.

Script:

local GroupId = 6741421
local MinimumRankToUseCommand = 9

function f(message)
	local TextService = game:GetService("TextService")
	local RunService = game:GetService("RunService")
	if RunService:IsStudio() then return message end
	local Success, Error = pcall(function()
		message = TextService:FilterStringAsync(message, game.CreatorId)
	end)
	if Success then
		local FilterSuccess, FilterError = pcall(function()
			message = message:GetNonChatStringForBroadcastAsync()
		end)
		if FilterSuccess then
			return message
		end
	end
	local result = ""
	for i = 1, string.len(message) do
		result = result .. "#"
	end
	return result
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local WarningGUI = script.WarningGUI:Clone()
		WarningGUI.Parent = Character.Head
	end)
	
	Player.Chatted:Connect(function(Message)
		local SplitMessage = Message:split(" ")
		if SplitMessage[1] == "!warn" and Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
			local NameOfPlayerToWarn = SplitMessage[2]
			local PlayerToWarn = game.Players:FindFirstChild(NameOfPlayerToWarn)
			local Reason = f(Message:split(NameOfPlayerToWarn)[2])
			
			local WarningGUI = PlayerToWarn.Character.Head.WarningGUI
			local CurrentWarnings = WarningGUI.Warnings
			
			CurrentWarnings.Value = CurrentWarnings.Value + 1
			WarningGUI.WarningLabel.Text = "W" .. CurrentWarnings.Value .. " - " .. Reason
			
			if CurrentWarnings.Value >= 3 then
				PlayerToWarn:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
			end
		end
	end)
end)

Does the logic flow as you expect?
By that I mean have you put prints in each logic section to check if that section is being processed.
I am also under the impression that if you want an if expression to depend on more than one true or false then the whole test part should be in brackets.