Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i use string.match on the whole string?

I'm making a anti capital system, it's supposed to kick someone when they speak in all caps, but I'm using the pattern "%u+" which only gets the first word. I want it to get the full sentence of what they have said.

I want it to check the whole sentence and check if it's in capitals, if it is then kick them

Heres my code

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local checkIfUpercase = string.match(msg, "%u+")
		print(checkIfUpercase)
		if string.upper(msg) == checkIfUpercase then
			player:Kick("Don't speak in all capitials!")
		end
	end)
end)

I'm guessing theres a different pattern I need to use, but idk.

1 answer

I tested this out:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(p)
	p.Chatted:Connect(function(msg)
	
		local upmsg = string.upper(msg)
			
		if msg == upmsg then
				
				p:Kick("STOP SHOUTING!!!!!!")
		
	end
	end)	
end)

what it does is puts msg in uppercase in a variable then checks if msg and upmsg are the same as you can see.

This discussion is preserved as it was. New answers, comments, and votes are closed.