Hi, I’ve got an inventory system and I’m using UIDragDetector to move the items around the slots. However the DragStart function doesn’t seem to run and doesnt let me drag any thing, let alone print any thing either unless UIDragDetector is a child of the ImageButton however this seems to allow the dragging of an image button even without an image set to it which I’ve added a check to see if it has an image or not and it still allows dragging. Any help is much appreciated cheers.
Script:
for i,slotFrame in pairs(hotbar:GetChildren()) do
if slotFrame:IsA("Frame") then
local imageButton = slotFrame:FindFirstChild("ImageButton")
if (imageButton) then
print("Found " ..imageButton.Name)
end
if imageButton.Image ~= "" then
local DragDetector = slotFrame:FindFirstChildWhichIsA("UIDragDetector")
print(imageButton.Name)
local SlotMouseIsIn
DragDetector.DragStart:Connect(function()
print("Drag Started")
StartPosition = slotFrame.Position
end)
DragDetector.DragEnd:Connect(function()
if SlotMouseIsIn ~= nil then
local Name1 = slotFrame.Name
local Name2 = SlotMouseIsIn.Name
slotFrame.Position = SlotMouseIsIn.Position
slotFrame.Name = Name2
SlotMouseIsIn.Position = StartPosition
SlotMouseIsIn.Name = Name1
else
slotFrame.Position = StartPosition
end
end)
for i,slotFrame2 in pairs(hotbar:GetChildren()) do
if slotFrame2:IsA("Frame") then
slotFrame2.MouseEnter:Connect(function()
if slotFrame2 ~= slotFrame then
SlotMouseIsIn = slotFrame2
end
end)
slotFrame2.MouseLeave:Connect(function()
SlotMouseIsIn = nil
end)
end
end
end
end
end
Output:
19:42:48.456 Found ImageButton - Client - LocalScript:100
19:42:48.456 ImageButton - Client - LocalScript:104
19:42:48.456 Found ImageButton (x5) - Client - LocalScript:100