Notification Keeps Saying Invalid Player

I’m making an admin command system which has a gameban command in it. My previous posts have showed a little what I want with a notification system.

For the game ban, I want it so it permanently bans them from my game. It keeps on saying invalid player when I type in my user correctly.

Example of what I want:

Admin: /gameban Comqts
User gets banned

If it’s an invalid player:
Admin: /gameban InvalidPlayer
Notification: Player is invalid.

What I keep getting

Admin: /gameban Comqts
Notification: Player is invalid.

SSS_COMMAND_SCRIPT

elseif string.sub(Message, 1 ,8) == "/gameban" and table.find(permissions.gameban, AdminLevel) then 
			
			local Target = game.Players:FindFirstChild(string.sub(Message,10,string.len(Message)-string.len(string.sub(Message,10))-1))
			
			
			if Target ~= nil then
				
				game:GetService("DataStoreService"):GetOrderedDataStore("PermBanList"):SetAsync(Target.UserId.."_GameBanned")
				
				Player:Kick("You have been banned from the game.")
				
			else
				
				game.ReplicatedStorage.Notification:FireClient(Client, "COMMANDS", "Player is Invalid")
				
			end;	

image

LOCAL_SCRIPT_NOTIFICATION

game.ReplicatedStorage.Notification.OnClientEvent:Connect(function(Type, CommandsList)
	local startergui = game:GetService("StarterGui")
	local text = ""
	if Type == "COMMANDS" then
		if typeof(CommandsList) == "string" then
			text = CommandsList
		else
			for _, command in pairs(CommandsList) do
				text = text .. "\n"..command
			end
		end
	end

	startergui:SetCore("SendNotification", {
		Title = "NOTIFICATION",
		Text = text
	})
end)

If anyone has suggestions, please help.

Print string.sub(Message,10,string.len(Message)-string.len(string.sub(Message,10))-1) out.

since the command syntax is ‘/gameban Comqts’ consider doing string.split(Message, ' ') to split that into a table {'/gameban', 'Comqts'}. You can then check if table[1] is ‘/gameban’ and table[2] will be your username reference.
You can use game:GetService("Players"):GetUserIdFromNameAsync('Comqts') to get the target’s UserId, be sure to handle if this fails.
Then use game:GetService("Players"):GetPlayerByUserId() with that ID. If it returns a Player, they are in the server, else it returns nil.

btw if Target ~= nil then is the same as if Target then

How would this look in the code? It’s hard to understand where to put the stuff you’re saying. With the “Comqts” part, I want it so like you could chat any user.