|
| 25 Jan 2017 11:47 AM |
for i,v in pairs(script.Parent:GetChildren()) do if v:IsA('TextLabel') then v.ImageButton.MouseButton1Down:connect(function() dragging = true for _, tool in pairs(plr.Backpack:GetChildren()) do if tool.TextureId == v.Image then hum:EquipTool(tool) end end end) v.ImageButton.MouseButton1Up:connect(function() if v.ImageButton.Position ~= UDim2.new(0,5,0,5) then -- find the closest textlabel, parent the imagebutton to it, and set UDim2 to 0,5,0,5 end end) end end
the imagebutton can be dragged, which allows it to be moved to a different slot in your toolbar. How would I find the closest textlabel?
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 25 Jan 2017 04:05 PM |
I came up with this but it didn't seem to work correctly
v.ImageButton.DragStopped:connect(function(x, y) local num = math.huge local original = v local ogButton = v.ImageButton local new for _, slot in pairs(script.Parent:GetChildren()) do if slot:IsA('TextLabel') then local slotpos = slot.AbsolutePosition.X if slotpos and slotpos - x < num then new = slot end end end if new:FindFirstChild('ImageButton') then local swap = new.ImageButton swap.Position = UDim2.new(0,5,0,5) swap.Parent = original end ogButton.Parent = new ogButton.Position = UDim2.new(0,5,0,5) end)
|
|
|
| Report Abuse |
|
|
OAuth2
|
  |
| Joined: 27 Nov 2016 |
| Total Posts: 751 |
|
|
| 25 Jan 2017 04:29 PM |
local target, dist = nil, 0 for _, v in pairs(gui:GetChildren()) do if v:IsA("GuiObject") then -- I'm not sure if this works tbh if not target then target, dist = v, (point.Position - v.Position).magnitude else if (point.Position - v.Position).magnitude < dist then target, dist = v, (point.Position - v.Position).magnitude end end end end -- Do stuff |
|
|
| Report Abuse |
|
|
| |
|
OAuth2
|
  |
| Joined: 27 Nov 2016 |
| Total Posts: 751 |
|
|
| 25 Jan 2017 04:42 PM |
| Magnitude works for any positions. |
|
|
| Report Abuse |
|
|
EXYZED
|
  |
| Joined: 09 Nov 2013 |
| Total Posts: 533 |
|
|
| 25 Jan 2017 05:56 PM |
Indeed. - Magnitude Magnitude is a term used across mathematics that means several things. In vector theory, the magnitude of a vector is the length of a vector.
http://wiki.roblox.com/index.php?title=Magnitude
This is very useful in your circumstances. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2017 06:11 PM |
Magnitude does not work with gui objects
|
|
|
| Report Abuse |
|
|
EXYZED
|
  |
| Joined: 09 Nov 2013 |
| Total Posts: 533 |
|
|
| 25 Jan 2017 06:16 PM |
Magnitude is math. that math is Pythagoras.
Pythagoras is vector-wise, stated here in this scenario: " Commonly, in ROBLOX and other situations in need of finding the distance between two points, it is also referred to as the distance formula. ROBLOX has a special property for Vector3 and Vector2 values that does the math for finding the magnitude of the value for you. Here is how it can be indexed: "
This math can be applied to POINTS, Specific to POSITION and SIZE. Does not mean that it cannot be applied to a GUI. GUI's also have vectors. |
|
|
| Report Abuse |
|
|
EXYZED
|
  |
| Joined: 09 Nov 2013 |
| Total Posts: 533 |
|
|
| 25 Jan 2017 06:18 PM |
Here is a perfect example of the usage of Magnitude in a 2D vector space. http://wiki.roblox.com/index.php?title=2D_triangles
X.Y_Z (EXYZED) |
|
|
| Report Abuse |
|
|