Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Snapdragon = require(game.ReplicatedStorage:WaitForChild("Snapdragon"))
- local LocalPlayer = game:GetService("Players").LocalPlayer
- local storeTbl = {
- true, true, true, true,
- true, true, true, true
- }
- local lastClosest = nil
- local function whichSlotisClosest(itemAbsolutePos)
- local objects = script.Parent.Slots:GetChildren()
- local minObj, min = objects[1], (objects[1].AbsolutePosition - itemAbsolutePos).Magnitude
- for i, v in pairs(objects) do
- if min > (v.AbsolutePosition - itemAbsolutePos).Magnitude then
- min = (v.AbsolutePosition - itemAbsolutePos).Magnitude
- minObj = v
- end
- end
- return minObj
- end
- local function areFramesOverlapping(myImageLabel)
- local guisDetectedAtPosition = LocalPlayer:WaitForChild("PlayerGui"):GetGuiObjectsAtPosition(myImageLabel.AbsolutePosition.X, myImageLabel.AbsolutePosition.Y)
- for _, v in pairs(guisDetectedAtPosition) do
- if v:IsA("GuiObject") and string.find(v.Name, "ItemPlaceholder") then
- return true
- end
- end
- return false
- end
- local controller = Snapdragon.createDragController(script.Parent.ItemPlaceholder2)
- controller:Connect()
- controller.DragEnded:Connect(function(callback)
- print(callback)
- local closestObj = whichSlotisClosest(controller.gui.AbsolutePosition)
- local overlappingUIs = areFramesOverlapping(controller.gui)
- if overlappingUIs ~= true and storeTbl[closestObj.Name] ~= false then
- controller.gui.Position = closestObj.Position
- if lastClosest ~= nil then
- storeTbl[lastClosest] = true
- end
- storeTbl[closestObj.Name] = false
- lastClosest = closestObj.Name
- end
- end)
- local controller2 = Snapdragon.createDragController(script.Parent.ItemPlaceholder)
- controller2:Connect()
- controller2.DragEnded:Connect(function(callback)
- local closestObj = whichSlotisClosest(controller2.gui.AbsolutePosition)
- local overlappingUIs = areFramesOverlapping(controller2.gui)
- if overlappingUIs ~= true then
- controller2.gui.Position = closestObj.Position
- if lastClosest ~= nil then
- storeTbl[lastClosest] = true
- end
- storeTbl[closestObj.Name] = false
- lastClosest = closestObj.Name
- end
- end)
Add Comment
Please, Sign In to add comment