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

Returning a error (ends with '%')???? Little help?

Asked by 7 years ago
function SendText(Tag,Text)
    local Removeable = {"!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","[","}","]","|","\",","~","`","<",",",">",".","","?","/"}
    for i = 1,string.len(Text) do
        for i = 1, #Removeable do
            if  string.find(string.lower(Text),Removeable[i]) then
                NewText1 = string.gsub(string.lower(Text), tostring(string.reverse(string.lower(Removeable[i]))),string.rep("x",string.len(Removeable[i])))
                Aproved = false
                NewText = NewText1
            end
        end
    end
    game.Workspace.ServerChat.NewChat:FireServer(Tag,NewText,true)
end

Error is:

Players.Player1.PlayerGui.Chat.ChatResponse:15: malformed pattern (ends with '%')

1 answer

Log in to vote
2
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

As the wiki states, "To search for a literal magic character, precede it by a % - for example, to look for a percent symbol, use %%."

So, all you have to do is escape all of the magic characters:

function SendText(Tag,Text)
    local Removeable = {"!","@","#","%$","%%","%^","&","%*","%(","%)","_","%-","%+","=","{","[","}","]","|","%\",","~","`","<",",",">","%.","","%?","/"}
    for i = 1,string.len(Text) do
        for i = 1, #Removeable do
            if  string.find(string.lower(Text),Removeable[i]) then
                NewText1 = string.gsub(string.lower(Text), tostring(string.reverse(string.lower(Removeable[i]))),string.rep("x",string.len(Removeable[i])))
                Aproved = false
                NewText = NewText1
            end
        end
    end
    game.Workspace.ServerChat.NewChat:FireServer(Tag,NewText,true)
end

Hope this helped.

0
This piece of code would really benefit from using the :gsub(), :lower(), and :reverse() syntax BlueTaslem 18071 — 7y
Ad

Answer this question