Hello guys. I’m trying to make drag-n-drop system for my inventory and hotbar system. But, when I start dragging, script somewhy unable to detect, when I releaze mouse button. But, while drag script had error which shifts it 36 pixels above (GuiInset size). So, this lead me to question: does GuiButtons block mouse connections?
(Script:)
local DragSlot, ActiveDrag, ActiveUp, ActiveSlot
local function SlotHold(StartX, StartY, Slot, Active)
if Active == true then
print("Drag started") <-- cfn be started by holding on button.
ActiveSlot = Slot
local MouseOffset = UDim2.new(0, StartX - Slot.AbsolutePosition.X, 0, StartY - Slot.AbsolutePosition.Y - 36)
DragSlot = Slot:Clone()
Slot.Visible = false
DragSlot.Size = UDim2.new(0, Slot.AbsoluteSize.X, 0, Slot.AbsoluteSize.Y) --bc I use scale inside scrolling frame, and I need persistant slot size.
DragSlot.Position = UDim2.new(0, StartX, 0, StartY) - MouseOffset
DragSlot.Parent = GuiSections.Inventory
ActiveDrag = Mouse.Move:Connect(function()
StartX = Mouse.X
StartY = Mouse.Y
DragSlot.Position = UDim2.new(0, StartX, 0, StartY + 36) - MouseOffset
end)
ActiveUp = Mouse.Button1Up:Connect(function()
StartX = Mouse.X
StartY = Mouse.Y
SlotHold(StartX, StartY + 36, nil, false)
end)
else
print("Drag ended") <-- this can be fired only if mouse released, but it never gets fired after I fixed 36 pixel bug.
if ActiveDrag then
ActiveDrag:Disconnect()
ActiveDrag = nil
ActiveUp:Disconnect()
ActiveUp = nil
end
local Success
for i = 1, #GUIforHoverTest, 1 do
local SlotStartPos = GUIforHoverTest[i].AbsolutePosition - 36
local SlotEndPos = SlotStartPos + GUIforHoverTest[i].AbsoluteSize
if SlotStartPos.X <= StartX and SlotEndPos.X >= StartX and SlotStartPos.Y <= StartY and SlotEndPos.Y >= StartY then
Success = i
break
end
end
if Success then
local HoverSlot = GUIforHoverTest[Success]
local SlotType = HoverSlot:GetAttribute("Type")
if SlotType == "Hotbar" then
print("Moving item into " .. tostring(HoverSlot.Name))
self:MoveToHotbar(ActiveSlot, string.match(HoverSlot.Name, "%d+"))
end
ActiveSlot:Destroy()
else
ActiveSlot.Visible = true
end
DragSlot:Destroy()
end
end
Some images:
(Holding pickaxe slot)
I reliazed mouse button, but no event fired!
Console