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

TextBox Release Focus and submiting?

Asked by 4 years ago

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)
0
What's happening at the moment? Vlym 19 — 4y
0
What do you mean? GreenBushed 13 — 4y
0
Try using TextBox.TextEditable = false flamekey 15 — 4y
0
Nope didn't work. GreenBushed 13 — 4y
View all comments (2 more)
0
mmm i'm waiting for you to look at my answer.. Luka_Gaming07 534 — 4y
0
not what im looking for. GreenBushed 13 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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()

Ad

Answer this question