How can I get a UI textbox to move when a button is clicked?

Hello Dev forum,
Today I was creating an intro screen with a play button and couldn’t figure out how to make a UI textbox move when the play button was clicked. So far I have made a script that makes the UI move to the position I want it to after 5 seconds. However, this script does not move it upon the click of the button. How can I edit this script to make it move the textbox? So far I have searched the dev forum and youtube for a solution. Linked below are the script and toolbox. Thanks for reading!

local object = script.Parent
object.AnchorPoint = Vector2.new(0.5, 0.5)
object.Position = UDim2.new(0.5, 0, 0.5, 0)

wait(2)

object:TweenPosition(UDim2.new(0.5, 0, 0.1, 0))

Screenshot 2021-12-29 154518

1 Like
object.MouseButton1Down:Connect(function()
     object:TweenPosition(UDim2.new(0.5, 0, 0.1, 0))
end)
1 Like

That doesn’t seem to be working, I have put the script under the textbox. Should I put it under the text button? I tried both of these however when putting it under the text button went up not the text box. Any way I can fix this?

If it’s a TextBox, you can bind to the TextBox.Focused event:

TextBox.Focused:Connect(function()
    -- tween here
end)

There’s also a TextBox.FocusLost event that you could bind to when the user stops editing the TextBox.

Hope that helped!

1 Like

I think you’re confusing two instances for one, for ex. you’re trying to move the textbox whilst the code only moves what it is set to move, like the TextButton.

  • I do not see the textbox anywhere in your toolbox so I can’t exactly provide any script but I can do this:
local TextBox_Parent = -- This needs to have the set path from the textbox.
local TextButton = -- This needs to have the set path from the textbutton. / Or leave the script inside the textbutton and just use script.parent until you find the textbox.

TextButton.MouseButton1Click:Connect(function()
	TextBox_Parent:TweenPosition(UDim2.new(0.5, 0, 0.1, 0));
end);
1 Like

Correction to what I stated. I have one text label and one text button. When the text button is clicked by a player (the play button) I want the play button to move off-screen, and the text label to move a bit off-screen then shift to the main menu. Sorry about the unclarity.

local TextLabel = -- This needs to have the set path from the TextLabel.
local TextButton = -- This needs to have the set path from the textbutton. / Or leave the script inside the textbutton and just use script.parent until you find the textbox.

TextButton.MouseButton1Click:Connect(function()
	TextLabel:TweenPosition(UDim2.new(0.5, 0, 0.1, 0)); -- Change the position to what want.
	TextButton:TweenPosition(UDim2.new(0.5, 0, 0.1, 0)); -- Change the positios to what want.
end);
1 Like