generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

GUI Drag Problem

Previous Thread :: Next Thread 
werts15 is not online. 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
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
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 is not online. 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
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
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 is not online. werts15
Joined: 27 Sep 2008
Total Posts: 1031
24 Jun 2012 10:07 PM
That works great! Thanks for all your help :)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image