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

How do I Make a non case sensitive OnChatted script?

for example, let's say the command is something like "/play", how would I make it so it detects even if the message they sent is "/PlaY" or "/pLaY" or "/PLAy" etc. this be so players wouldn't struggle when getting the right command.

NOTE: this is not the correct scripting

Player.Chatted:Connect(function(Message)
if Message == "/play" then -- this would detect only "/play" but not "/Play" or "/PLAY" or "/PlAy"
--script here

2 answers

✓ Accepted answer

You can use string.lower().

Example:

local command = string.lower("Hi LoL") --> "hi lol"

I recommend using string.lower to the message. That way, you can compare the message which is now all lowercase to "/play" which is also all lowercase.

This is what I mean...

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local command = string.lower(message) --all-lowercases the message
		
		if command == "/play" then --compares
			print("Hello world!") --your code
		end
	end)
end)

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