Im trying to create a drag and drop system however ive come across a problem, for some reason the mouseisin variable is always the same button. I know what the problem is i just have no idea how i can fix it
function Sorting.Drag()
for _, v in Sorting.uiElements do
local Imagelabel = v.ImageLabel
local Drag = Imagelabel:FindFirstChildOfClass("UIDragDetector")
if not Drag then print("Drag not found".. v.Name) continue end
local Bool = v:FindFirstChildOfClass("BoolValue")
if not Bool then print("Bool not found") continue end
local MouseIsIn
local StartPosition
Drag.DragStart:Connect(function()
print("Drag started")
StartPosition = Imagelabel.Position
end)
Drag.DragEnd:Connect(function()
print("Drag Ended")
if MouseIsIn ~= nil then
if MouseIsIn == v then return end
local NewBool = MouseIsIn:FindFirstChildOfClass("BoolValue")
local Tool = Bool:FindFirstChildOfClass("Tool")
if not Tool then print("Tool not found") return end
Tool.Parent = NewBool
print(Tool.Parent.Parent.Name)
--MouseIsIn.ImageLabel.Visible = true
--Imagelabel.Image = 0
print("Changed Image")
--MouseIsIn = nil
end
Imagelabel.Position = StartPosition
end)
v.MouseEnter:Connect(function()
MouseIsIn = v
if Bool.Value then
print("item "..v.Name)
return
end
print("no item "..v.Name)
end)
end
end