Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)

Ad

Answer this question