I need to make draggable cards (well it’s not a card game) for my loadout system. DataStore and gui setup function are all done and i’ll need to make the drag and drop system.
However the issue is: input.Position from UserInputService uses vector2 as i’m forced to use offset instead the scale i wanted in UDim2. Here’s the vid i did watch How to Move a GUI on the Screen (Drag) - Roblox Studio Tutorial - YouTube
Though the x / viewportSize.X
does not work for this as i searched from google…
Here’s the code:
local function updateInput(obj,input)
local delta = input.Position - dragstart
local curGui = clickable[top]
local pos = UDim2.new(curGui.startpos.X.Scale + delta.X,curGui.startpos.X.Offset,curGui.startpos.Y.Scale + delta.Y,curGui.startpos.Y.Offset)
game:GetService('TweenService'):Create(obj,TweenInfo.new(dragspeed),{Position = pos}):Play()
end
other lines:
UIS.InputBegan:Connect(function(input,gp)
if not gp and (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
dragstart = input.Position
local pos = input.Position
local under = PlayerGui:GetGuiObjectsAtPosition(pos.X, pos.Y)
for a,obj in pairs(under) do
local stop = false
for i,v in pairs(clickable) do
if tostring(obj) ~= tostring(i) then
top = nil
else
top = under[a]
clickable[top].startpos = top.Position
stop = true
end
end
if stop then
break
end
end
--if clickable[top].bool ~= nil then
--clickable[top].startpos = top.Position
--end
end
end)
UIS.InputChanged:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch)and isMouseButtonDown(Enum.UserInputType.MouseButton1) and top ~= nil then
updateInput(top,input)
end
end)