Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I fix this input bug with the changed event?

So, I'm trying to get user input via textbox and the changed event, and it works.

Problem is, instead of collecting the input once the user clicks away or presses enter, it detects every time a new letter is added. I used print to collect an output of what happens so hopefully anyone who sees this thread can understand this better: (im putting this in a code block because otherwise it does not stack; this is directly from the output of my game)

b
bu
bug
bugs
bugs :
bugs :(

My script takes this user input and places it into a billboard gui above the user's head (which works perfectly,) although, because it is stacked like this, all the letters are bunched up together and you cannot see the actual word.

Take a look at the script:

player = game.Players.LocalPlayer
character = player.Character

script.Parent.Changed:connect(function(p)
	if p == 'Text' then
		print(script.Parent[p])
		local bg = Instance.new("BillboardGui")
			bg.Parent = character.Head
			bg.Size = UDim2.new(1, 0, 1, 0)
			bg.StudsOffset = Vector3.new(0, 2, 0)
		local frame = Instance.new("Frame")
			frame.Parent = bg
			frame.Size = UDim2.new(1, 0, 1, 0)
			frame.BackgroundTransparency = 1
		local text = Instance.new("TextLabel")
			text.Parent = frame
			text.Position = UDim2.new(0.25, 0, 0.25, 0)
			text.Size = UDim2.new(0.5, 0, 0.5, 0)
			text.Text = script.Parent[p]
			text.BackgroundTransparency = 1
			text.TextColor3 = Color3.new(1, 1, 1)
			text.Font = "ArialBold"
			text.FontSize = "Size24"
			
	end	
end)

Anyone have any suggestions?

1 answer

✓ Accepted answer

Try using the FocusLost event instead of the Changed event.

This should require no change to your code (except obviously removing the if p == 'Text' check)

This discussion is preserved as it was. New answers, comments, and votes are closed.