Having trouble setting TextLabel Text to TextBox content + filter

Hello! I’m aiming to create a system in which whatever the player types into the TextBox, is replicated for the ENTIRE server to see on a TextLabel inside a SurfaceGui. I’ve had a lot of trouble, and I’ve been trying many different methods, but to no avail. I’ve never wondered into these type of code, but I’m hoping you can help me out.

Here’s a ServerScript in ServerScriptService

local SetCinemaName = game.ReplicatedStorage.RemoteEvents.SetCinemaName
SetCinemaName.OnServerEvent:Connect(function(Player, Name)
	local Filter = game:GetService("TextService"):FilterStringAsync(Player.UserId, Name)
	local Check = Filter:GetNonChatStringForBroadcastAsync()
	local PlotOwner = game.Workspace.GamePlots:GetDescendants("PlotOwner")
	if PlotOwner.Value == Player.Name then
		PlotOwner.Parent.Parent.Parent.CinemaName.SurfaceGui.CinemaName.Text = Check

Here’s a client [LocalScript] inside the TextBox

local Confirm = script.Parent.Parent.CompleteButton
local Input = script.Parent
local Event = game.ReplicatedStorage.RemoteEvents.SetCinemaName

	local Name = Input.Text
	if string.len(Name) > 1 or string.len > 20 then return end

This looks like a pretty complete code set to me. What’s the exact trouble you’re having?

I can see something that might cause an issue though when I skimmed through the code. It’s from your client-side code. You’re trying to compare a function (string.len) to a number (20) so that’s going to cause an error. Mirror the first check with the second.

Once that error is resolved, your next problem is your repeated comparison operators. Your comparison currently reads as “if name’s length is greater than one or greater than 20, do nothing”. That means the name length has to be 0. You probably meant to do “is less than one”. Flip the sign.

Make sure to check your console and proofread your code, helps in the long run.

Quick fix:

Confirm.MouseButton1Click:Connect(function ()
    local Name = Input.Text
    local NameLength = string.len(Name) -- #Name also works here
    -- This was your issue: comparing a function to a number as well as
    -- a confusing check.
    if NameLength > 1 or NameLength < 20 then return end

And then as a helping hand, you’ll want to get some sanitisation on that remote. An exploiter can fire a string that’s 0 characters long or more than 20 characters and your server will accept that as genuine. The client is good to not fire the event if the name is less than 1 character or greater than 20 but when the server receives a name it should do a hard cut off and use whatever’s left as the given name.

SetCinemaName.OnServerEvent:Connect(function (Player, Name)
    -- Any time a name is given to the RemoteEvent, enforce that the name
    -- be characters 1-20 of the string. If under 20 characters, return the
    -- same name. If over 20 characters, return only the first 20 characters.
    Name = string.sub(Name, 1, 20)

Word of caution that the above may cut off Unicode characters. If you have localisation support, consider switching to uf8.len or a custom string length counter that respects graphemes (e.g. emojis with skin tone modifiers are 2 graphemes, an emoji is one grapheme but can be more than 1 byte or “letter” - so allow up to 20 graphemes instead of 20 bytes/letters).

Ah and then the other thing is your GetDescendants(“PlotOwner”). The string in the brackets will be discarded and GetDescendants returns a table. You’ll need to change this to a different implementation. I don’t know how you put your PlotOwner values in the Workspace though so I will need to see an example before I comment on that.