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

How to make a string case-Insensitive?

Asked by 8 years ago

In my game a function triggers if a player says a certain string. So if this certain string is "Apple" and the player says "apple" or even "ApPlE" the function will not trigger.

object = "Apple"

player.Chatted:connect(function(msg)
    if msg == object then
        --code
    end
end)

2 answers

Log in to vote
1
Answered by
Omarstein 100
8 years ago

User string.lower() on both so that when the player types something, both the "object" and the "msg" are converted into lowercase and compared.

object = "Apple"

player.Chatted:connect(function(msg)
    if string.lower(msg) == string.lower(object) then
        --code
    end
end)

0
tyvm :) tigergo4 83 — 8y
0
Ninja'd me by this much Pyrondon 2089 — 8y
Ad
Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

Convert the string to lowercase, and then check a lowercase string.

object = "apple"

player.Chatted:connect(function(msg)
    msg = msg:lower()
    if msg == object then
        --code
    end
end)

Hope this helped.

0
ty! tigergo4 83 — 8y
0
No problem. Pyrondon 2089 — 8y

Answer this question