werts15
|
  |
| Joined: 27 Sep 2008 |
| Total Posts: 1031 |
|
|
| 24 Jun 2012 09:40 PM |
I am trying to make an ImageButton be able to be dragged. Everybody says to look in free models for scripts, and learn off those. I found this script:
moveGui=false xOrig,yOrig=0,0 script.Parent.MouseButton1Down:connect(function(x,y) xOrig,yOrig=x,y moveGui=true end) script.Parent.MouseMoved:connect(function(x,y) if moveGui then for _,a in pairs(script.Parent.Parent:GetChildren()) do a.Position=UDim2.new(a.Position.X.Scale,a.Position.X.Offset+x-xOrig,a.Position.Y.Scale,a.Position.Y.Offset+y-yOrig) end xOrig,yOrig=x,y end end) script.Parent.MouseButton1Up:connect(function(x,y) moveGui=false end)
I understand mostly why it works, but it uses GetChildren() which makes everything in the ScreenGUI able to drag. When I ran it it dragged everything when I dragged the tree. I want to get rid of the GetChildren(), but I don't want it to break. I tried to put the parent as the ImageButton, but when I did that it tried to make the script drag, because of GetChildren(). If anyone can help me fix the code without breaking it, I would really appreciate it. Thanks in advance :) |
|
|
| Report Abuse |
|
|
|
| 24 Jun 2012 09:43 PM |
Dude, you realize that there's a Draggable property? As long as the Active and Draggable properties are set to true, you'll be able to drag it.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." - Rick Cook |
|
|
| Report Abuse |
|
|
werts15
|
  |
| Joined: 27 Sep 2008 |
| Total Posts: 1031 |
|
|
| 24 Jun 2012 09:47 PM |
That would have been useful to know... I just tried it and it worked. But now I have a different question. How do you make it so it can only be dragged left or right? |
|
|
| Report Abuse |
|
|
|
| 24 Jun 2012 10:02 PM |
Unless you want to make a custom drag system, this is the best I can think of:
local yscale = script.Parent.Position.Y.Scale local yoffset = script.Parent.Position.Y.Offset while wait() do script.Parent.Position = UDim2.new(script.Parent.Position.X.Scale, script.Parent.Position.X.Offset, yscale, yoffset) end
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." - Rick Cook |
|
|
| Report Abuse |
|
|
werts15
|
  |
| Joined: 27 Sep 2008 |
| Total Posts: 1031 |
|
|
| 24 Jun 2012 10:07 PM |
| That works great! Thanks for all your help :) |
|
|
| Report Abuse |
|
|
|
| 25 Jun 2012 12:58 PM |
No problem. ;)
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." - Rick Cook |
|
|
| Report Abuse |
|
|