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

How do make a GUI button move by onClicked?

Hi, I am trying to find a script would allow a GUI button to move when a player use an onClicked function.
What would the script be? (Just make an example script, but don't make the script too complicated!)

1 answer

✓ Accepted answer
local tweened = false
script.Parent.MouseButton1Click:connect(function()
if not tweened then
tweened = true
script.Parent:TweenPosition(UDim2.new(0, 15, 0, 15)) --change the numbers to wherever you want the button to go, TweenPosition makes it glide smoothly
elseif tweened then
tweened = false
script.Parent:TweenPosition(UDim2.new(0, 0, 0, 0)) --this is the button's original position
end
end)

13 comments

0

No, I want a script to use the "Position" function not set by draggable. So, I can set the position to anywhere I want. Do you know what I mean?

1

You mean like, the button would follow your mouse without you holding any of the mouse buttons down?

0

No. When a mouse clicks on it the position change. That's why I need to find a script which would move the Menu button out of the way while the main menu is opening. Do you know what I mean?

1

I see what you mean. I'll edit my answer to fit your needs.

1

Actually one more question. Where would the script go, and what do you mean by an onClicked function.

0

I would put it in the TextButton where the button is formed. And I thought onClicked function would be an object which it clicked from baseplate (for e.g. Clicking the red and green buttons). Do you mean MouseButton1Click?

0

Sorry, did I confuse yourself?

2

So, you want a button where when you click it, it moves to a different position?

0

Yes.

0

Is it possible to make move as classic (not smooth move, like one to another without a smooth)?

2

Yes. Just make it script.Parent.Position = UDim2.new(0, 15, 0, 15).

0

Thank you very much, it worked!

1

Yay :D

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