String.len don't work with textBox text

  1. What do you want to achieve? Keep it simple and clear!
    So basically i’m making an gang system and gang name shouldn’t be more than 16 char. i’m using string.len to get amount of characters, and for some reason it always says what “Gang name should be less than 16 char.” even if it 2 chars. Idk what is the problem

  2. What is the issue? Include screenshots / videos if possible! Described in 1.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I was searching on Dev Forum and found few topics, and it should work idk what is problem.

Code:

local LCS = script.Parent.Parent.Parent.LCscreen
local GangParametersGUI = script.Parent.Parent.Parent.GangParameters
local Button = script.Parent
local GangCEvent = game.Workspace.GangsEvents.GangCEvent
local GangNameBox = GangParametersGUI.GangNameBox
local GangNameText= GangNameBox.Text
local GangNameLen = string.len(GangNameText)
print(GangNameLen)
local GangTypeVal = script.Parent.Parent.TextLabel.GangType
Button.MouseButton1Click:Connect(function()
	if GangNameLen < 16 then
	GangCEvent:FireServer(GangNameBox.Text, GangTypeVal.Value)
	GangParametersGUI.Visible = false
		LCS.Visible = true
	else
		Button.Text = "Gang Name Should be less than 16 char."
		wait(3)
		Button.Text = "Create Gang!"
	end
end)
1 Like

Alright now, after i put placeholder into placeholder instead of text property it now goes to next page, but even if chars > 16.

Print out GangNameText and GangNameLen at the same time.

right below this add this

`local GangNameLen = string.len(GangNameBox.Text)’

you are not redeclaring the string length from what i see there

everytime the mouse is clicked you need to recheck the string length

1 Like

Well instead of getting string from textbox now i get it from other script inside of textbox, here is it:

local Box = script.Parent
local GangNameVal = script.Parent:FindFirstChild("GangName")
Box.FocusLost:Connect(function()
	GangNameVal.Value = Box.Text
end)

Now i get string from value.
Also new code:

local LCS = script.Parent.Parent.Parent.LCscreen
local GangParametersGUI = script.Parent.Parent.Parent.GangParameters
local Button = script.Parent
local GangCEvent = game.Workspace.GangsEvents.GangCEvent
local GangNameBox = GangParametersGUI.GangNameBox.GangName
print(GangNameBox.Value)
local GangNameText= GangNameBox.Value
local GangNameLen = string.len(GangNameText)
print(GangNameLen)
local GangTypeVal = script.Parent.Parent.TextLabel.GangType
Button.MouseButton1Click:Connect(function()
	if GangNameLen < 16 then
	GangCEvent:FireServer(GangNameText, GangTypeVal.Value)
	GangParametersGUI.Visible = false
		LCS.Visible = true
	else
		Button.Text = "Gang Name Should be less than 16 char."
		wait(3)
		Button.Text = "Create Gang!"
	end
end)

Well anyways this don’t work, it still go to next page if char >16. Also here is prints:
image
Other print which string.len is just don’t print bruh

could even change this line to this and get rid of alot of the above variables

if string.len(GangNameBox.Text) < 16 then
1 Like

Well thanks this work! (30 lettersssssss)

1 Like