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

How do make a GUI button move by onClicked?

Asked by 9 years ago

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

Log in to vote
2
Answered by 9 years ago
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)
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? BenHall4433 0 — 9y
1
You mean like, the button would follow your mouse without you holding any of the mouse buttons down? bobafett3544 198 — 9y
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? BenHall4433 0 — 9y
1
I see what you mean. I'll edit my answer to fit your needs. bobafett3544 198 — 9y
View all comments (9 more)
1
Actually one more question. Where would the script go, and what do you mean by an onClicked function. bobafett3544 198 — 9y
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? BenHall4433 0 — 9y
0
Sorry, did I confuse yourself? BenHall4433 0 — 9y
2
So, you want a button where when you click it, it moves to a different position? bobafett3544 198 — 9y
0
Yes. BenHall4433 0 — 9y
0
Is it possible to make move as classic (not smooth move, like one to another without a smooth)? BenHall4433 0 — 9y
2
Yes. Just make it script.Parent.Position = UDim2.new(0, 15, 0, 15). bobafett3544 198 — 9y
0
Thank you very much, it worked! BenHall4433 0 — 9y
1
Yay :D bobafett3544 198 — 9y
Ad

Answer this question