I am working on an item dragging inventory and i have came across a problem where things get picked and placed at wrong places and i don’t know what i did wrong…
Heres an video explaining my issue:
robloxapp-20210216-2215344.wmv (489,9,KB)
and Heres my code:
local RunService=game:GetService("RunService")
local CurrentObject=nil
local CurrentObjectsTable={}
local CurrentParent=nil
local Holding=false
local Dragging=false
local Player=game:GetService("Players").LocalPlayer
local StarterGui=Player:WaitForChild("PlayerGui")
local Inventory=script.Parent
local Backpack=Inventory:WaitForChild("Backpack")
local Items=Backpack:WaitForChild("Items")
local HotSlots=Backpack:WaitForChild("HotSlots")
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local Inventories=ReplicatedStorage:WaitForChild("Inventories")
local PInventory=Inventories:WaitForChild(Player.Name.."_INV_"..Player.UserId)
local ContextActionService=game:GetService("ContextActionService")
Mouse=Player:GetMouse()
Mouse.Button1Down:Connect(function()
if CurrentParent~= nil and CurrentObject~= nil then
CurrentObject.Parent=Inventory
print(CurrentObject)
Dragging=true
end
end)
Mouse.Button1Up:Connect(function()
Dragging=false
local GUIs = StarterGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y-36)
for i=1,#GUIs do
local CurrentSelection=GUIs[i]
if CurrentSelection:FindFirstChild("ItemHolder") and CurrentObject~=nil then
local t=#CurrentSelection.ItemHolder:GetChildren()
if t>=2 then
return
else
CurrentObject.Parent=CurrentSelection.ItemHolder
end
end
end
end)
Mouse.Move:Connect(function()
if Dragging then return end
local GUIs = StarterGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y-36)
CurrentObjectsTable=GUIs
for i=1,#CurrentObjectsTable do
local CurrentSelection=CurrentObjectsTable[i]
if CurrentSelection.Parent==Items and not Dragging then
CurrentObject=CurrentSelection
CurrentParent=Items
--print(CurrentObject)
--elseif Dragging and CurrentSelection:IsDescendantOf() then
end
end
end)
RunService.RenderStepped:Connect(function()
if Dragging then
CurrentObject.Position=UDim2.new(0,Mouse.X,0,Mouse.Y)
end
end)