Hello Its Sam Iam trying to make a drag drop inventory system
But i dont know how to make a drag and then drop and it will be children of the new frame ?
How to do something like the picture ?
Or you can check Explore :The New World inventory system i need something similar to it !
Any help is appriciated Thanks
You will need to use the GetGuiObjectsAtPosition() function and set the Active property of the item frame to true and use a script to set the frame’s draggable property to true
local frame = script.Parent
local dragToggle = nil
local dragSpeed = 0.9
local dragStart = nil
local startPos = nil
local function updateInput(input)
local delta = input.Position - dragStart
local position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X,
startPos.Y.Scale, startPos.Y.Offset + delta.Y)
game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed), {Position = position}):Play()
end
frame.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
dragToggle = true
dragStart = input.Position
startPos = frame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragToggle = false
end
end)
end
end)
UIS.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
if dragToggle then
updateInput(input)
end
end
end)
First i want to point out that you don’t need to use TweenService but just frame.Draggable = true also your script is more complicated than how it should be.
local dragging = false
uis.InputBegan:Connect(function(input, processed)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
local state = input.UserInputState
if state == Enum.UserInputState.Begin then
dragging = true
else if state == Enum.UserInputState.End then
dragging = false
end
end
end)
while true do
if dragging then
local pos = input.Position
local guiObjectsAtPosition = PlayerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
for i, v in pairs(guiObjectsAtPosition) do
if table.find(itemsFrame:GetChildren(), v) then --here it checks if the object at position is a child of the items frame
--Set the parent of the objects that is being dragged
end
end
else
--Set the frame of which the object being dragged was child of as parent of it
end
wait(0.1)
end
Oh sorry i rforgot to change it. just make an input variable
local dragging = false
local uisInput = nil
uis.InputBegan:Connect(function(input, processed)
uisInput = input
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
local state = input.UserInputState
if state == Enum.UserInputState.Begin then
dragging = true
else if state == Enum.UserInputState.End then
dragging = false
end
end
end)
while true do
if dragging then
local pos = uisInput.Position
local guiObjectsAtPosition = PlayerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
for i, v in pairs(guiObjectsAtPosition) do
if table.find(itemsFrame:GetChildren(), v) then --here it checks if the object at position is a child of the items frame
--Set the parent of the objects that is being dragged
end
end
else
--Set the frame of which the object being dragged was child of as parent of it
end
wait(0.1)
end
Oh…didn’t know because last time i used it, it wasn’t. So now you will need to find another way to detect drag start and ends.
uis.InputBegan:Connect(function(input, processed)
uisInput = input
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
local state = input.UserInputState
if state == Enum.UserInputState.Begin then
loca inputPos = input.Position
local guiObjectsAtPosition = playerGui:GetGuiObjectsAtPosition(inputPos.X, inputPos.Y)
for i, v in pairs(guiObjectsAtPosition) do
if table.find(itemsFrame:GetChildren(), v) then --here it checks if the object at position is a child of the items frame
dragging = true
end
end
else if state == Enum.UserInputState.End then
dragging = false
end
end
end)