Printing how many letters are in a text box

I am doing this as kind of a test for a matchmaking system. I have no clue why its not working all the way. I need it to update every time something new is added to the textbox. it only prints right as i join the game. Any idea?

local TextBox = script.Parent.Type
local Text = TextBox.Text
local Letters = string.len(Text)
print(Letters)
1 Like

You need to have an event trigger in your code for when the Text property is changed.

local TextBox = script.Parent.Type

TextBox:GetPropertyChangedSignal("Text"):Connect(function() --This looks for when the text property has changed
     local Text = TextBox.Text
     local Letters = string.len(Text)
     print(Letters)
end)

I actually didnt think about that, thanks for the help!

I get no errors and I did implement it correctly. Im sorry, im quite new to Luau

Are you having issues with the code? Sorry just confused on that.

Yes, i am having problems.

((((((((((((((((((((((((((((((((((((((30 bypass

Alright, is this code running in a Local Script? The icon in the explorer window would look this:

image

This makes sure the code runs on the client, which is needed to get their typing input.

so sorry for wasting your time, when you gave me the example code, I just typed it up (because i like my scripts a certain way) and made it GetPropertyChangedSignal("text") instead of GetPropertyChangedSignal("Text"). so yes, i was actually getting an error

No worries, I’m just browsing DevForum right now. Glad the issue was an easy fix.

so its just multiplying the number I had when I joined, every time i hit a new letter it just multiplies it by 1 (which of course doesnt change the actual number) it even does it when i hit back space

I want it to print another print every time i add a letter/number

1 Like

The first issue with the multiplication I’m not sure what would be causing that. I’ll work on a solution for the second issue.

EDIT: Below script will only print when a non-space character is added and will only print out the number of non-space characters. This is handled by using string.gsub to replace spaces with empty strings.

local TextBox = script.Parent
local lastStringNoSpaces = ""

TextBox:GetPropertyChangedSignal("Text"):Connect(function() --This looks for when the text property has changed
	local Text = string.gsub(TextBox.Text," ","")
	local Letters = string.len(Text)
	if Text ~= lastStringNoSpaces then
		print(Letters)
		lastStringNoSpaces = Text
	end
end)
1 Like

I forgot to tell you, I figured it out. Thank you so much for all the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.