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

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

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

✓ Accepted answer

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.

1 comment

0

This piece of code would really benefit from using the :gsub(), :lower(), and :reverse() syntax

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