How do I change text via a TextBox when a Player types in it

What I’m trying to acomplish is fairly simple, when a Player types in the TextBox and whatever they type it will get filtered via the ChatService before it’s displayed on a Part via a TextLabel.

My main question is how do I fact check this, if a Player types in the TextBox is there a way to confirm if there is string in that TextBox and when they press the SubmitButton it would automatically be changed on the TextLabel.

Here’s the code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ChatService = game:GetService("Chat")
local RemoteEvent = game.ReplicatedStorage.BoothEvent
local BoothGui = game.StarterGui.BoothGui
local LocalPlayer = Players.LocalPlayer
local PlayerBoothGui = LocalPlayer.PlayerGui:WaitForChild("BoothGui")

RemoteEvent.OnClientEvent:Connect(function()
	PlayerBoothGui.Enabled = true
	PlayerBoothGui.Frame.BackgroundTransparency = 0
	
	local SubmitButton = PlayerBoothGui.Frame.SubmitButton
	local CloseButton = PlayerBoothGui.Frame.CloseButton
	local BoothText = game.Booth.Header.SurfaceGui.FrameGui.TextGui.Text
	
	CloseButton.MouseButton1Click:Connect(function()
		if PlayerBoothGui.Enabled == true then
			PlayerBoothGui.Enabled = false
			 
			game.ReplicatedStorage.ChatEvent.OnServerEvent:Connect(function(player, BoothText) 
				ChatService:FilterStringForBroadcast(BoothText, player)
				
					-- Here I'd go through the actual changing of the text
				
			end)

		end 
	end)
	
	print("RemoteEvent fired Successfully")
end)

Any help will be appreciated! :smile: :cyclone:

It would go something like

local TextBox = nil --path textbox GUI here
If TextBox.Text ~= nil then --no need to touch stuff below
BoothText = TextBox.Text
end

I think this is what you’re saying?

Use an if statement to check if the text is there if there is no text just do

local ExampleBox = Example
if ExampleBox.Text ~= "" then
print("TEXT!")
end
2 Likes

They can’t be nil
OnlyTwentyCharacters

1 Like

Yeah that’s what I ended up doing but I had an error with the chat filtering.

Here’s the code.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ChatService = game:GetService("Chat")
local RemoteEvent = game.ReplicatedStorage.BoothEvent
local BoothGui = game.StarterGui.BoothGui
local LocalPlayer = Players.LocalPlayer
local PlayerBoothGui = LocalPlayer.PlayerGui:WaitForChild("BoothGui")

RemoteEvent.OnClientEvent:Connect(function()
	PlayerBoothGui.Enabled = true
	PlayerBoothGui.Frame.BackgroundTransparency = 0
	
	local SubmitButton = PlayerBoothGui.Frame.SubmitButton
	local CloseButton = PlayerBoothGui.Frame.CloseButton
	local TextBox = BoothGui.Frame.Frame.TextBox
	local BoothText = game.Workspace.Booth.Header.SurfaceGui.Frame.TextLabel.Text

	game.ReplicatedStorage.ChatEventFilter.OnServerEvent:Connect(function(player, BoothText) 
		ChatService:FilterStringForBroadcast(BoothText, player)
		
		SubmitButton.MouseButton1Click:Connect(function()
			if TextBox.Text ~= nil then --  
				BoothText = TextBox.Text 
				if TextBox == BoothText then
					if PlayerBoothGui.Enabled == true then
						PlayerBoothGui.Enabled = false
						print("Text Changed")
					end
					
				end
			end
		end)
	end)
	
	CloseButton.MouseButton1Click:Connect(function()
		if PlayerBoothGui.Enabled == true then
			PlayerBoothGui.Enabled = false
		end 
	end)
end)

Keep in mind I know that it’s a Local Script and the code needs to be in a server script but my main issue now is that how do I fix that lol do I simply use the filtering chat server in a server script and then fact check the texting because I also want to make it where when a player finishes typing it’s done by a Submit button.

1 Like

If it’s anything gui based, keep it on the client

The texttt can’t equalll nilll…
image

Do I just replace it with an empty " "

Yes, it’ll allways have an empty string if there is no text

1 Like

I don’t think I can keep it client based because of this

This is caused by the filteringchat service btw

Oh okay that makes alot more sense

use

Textbox.Text = "text"

What?
OnlyTwentytwoCharacters223412321

Why not use just this ,if TextBox.Text ~= “”

Yeah so problem is basically this.

game.ReplicatedStorage.ChatEventFilter.OnServerEvent:Connect(function(player, BoothText) 
		ChatService:FilterStringForBroadcast(BoothText, player)
		
		SubmitButton.MouseButton1Click:Connect(function()
			if TextBox.Text ~= "" then 
				BoothText = TextBox.Text 
				if TextBox == BoothText then
					if PlayerBoothGui.Enabled == true then
						PlayerBoothGui.Enabled = false
						print("Text Changed")
					end
					
				end
			end

Do I seriously have to make a whole seperate script just to filter the text on the server.

first make sure its on the client only the client can detect textboxes

Yeah it is on the Client though

is it firing from client the text on the server text will also be “”

Here try this instead TextService | Roblox Creator Documentation

1 Like