Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I Make a non case sensitive OnChatted script?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
3 years ago

You can use string.lower().

Example:

local command = string.lower("Hi LoL") --> "hi lol"
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question