Player chat script not working

Anybody know why this isn’t working, nothing is happening

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local message = msg:lower()
		if message:match("/id") then 
			local splitMessage = message:split(" ")
			print(splitMessage)
			if splitMessage == nil then
				local clone = game.ReplicatedStorage.ID:Clone()
                clone.Parent = player.PlayerGui
		        end
			if splitMessage ~= nil then
					if game.Players:FindFirstChild(splitMessage) then
					       	local clone = game.ReplicatedStorage.ID:Clone()
				                clone.Parent = player.PlayerGui
					else
						return("No Player Found!")
					end
				end
			end
		end
	end)
end)

Some of the ends might not be correct as I had to edit some of the code for privacy reasons, aswell as the formating might be incorrect. I apologize.

oh it could be because im doing :lower even if it doesnt need to be

Try splitting the message before because right now you’re just checking if the message is “/id” without any arguments.

yes but it works even tho i check after, like stuff prints out

no, doing lower won’t affect this. Using string.split and string.find would work better at the start. Like this:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local splitmsg = msg:split(" ")
		splitmsg[1] = splitmsg[1]:lower()
		
		if splitmsg[1] == "/id" then 
			if splitmsg[2] == nil then
				local clone = game.ReplicatedStorage.ID:Clone()
                		clone.Parent = player.PlayerGui
		        end
			if splitmsg[2] ~= nil then
					if game.Players:FindFirstChild(splitmsg[2]) then
					       	local clone = game.ReplicatedStorage.ID:Clone()
				                clone.Parent = player.PlayerGui
					else
						return("No Player Found!")
					end
				end
			end
		end
	end)
end)

Hi, I think this would work as well but I just realized I did splitMessage without getting the table

I had to do splitMessage[2]

oops