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

TextBox Release Focus and submiting?

I wanna make a script that in a textbox detects a string then will replace it with something else then immediately submit it afterwords, in other words as in submit like if you are chatting then you press enter it submits the chat. I know I could use the chat RemoteEvent but I want to use this on all gui's not just chat.

local blacklist = {
	'badword',
	'badword2',
	}



local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local pgui = plr.PlayerGui

RunService.RenderStepped:Connect(function()
	for i,v in pairs(pgui:GetDescendants()) do
		if v.ClassName == 'TextBox' or v.ClassName == 'TextLabel' or v.ClassName == 'TextButton' then
			for b,n in pairs(blacklist) do
				if string.find(v.Text,n) then
					v.Text = "#&*^(@"
					-- Not sure what to put here
				end
			end
		end
	end
end)

6 comments

0

What's happening at the moment?

0

What do you mean?

0

Try using TextBox.TextEditable = false

0

Nope didn't work.

0

mmm i'm waiting for you to look at my answer..

0

not what im looking for.

1 answer

So, to replace something in a string with something else you do

local NewString = string.gsub("String Here", "Bad String Here", function(String)
	return string.rep("Replacement Character Here", #String)
end)

Basically what the above code does is:

  • Search for the Bad String
  • Replace it with the Third parameter which is in this case a function
  • The function repeats the Replacement Character String Length amount of times

If you are filtering chat you should use TextService:FilterStringAsync()

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