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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
5 years ago

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.

Ad

Answer this question