Just use this script and tell me what errors it prints and give me the code so I can Implement it with the OOP structure.
I already implemented it within the OOP Structure, just imagine draggableFrame is self.Instance because it is
Update Function:
local function Update(draggableFrame,input:InputObject)
local delta = input.Position - StartingPoint
local parentSize = Main.Size
local scaleX = delta.X / parentSize.X
local scaleY = delta.Y / parentSize.Y
draggableFrame.Position = UDim2.new(oldPos.X.Scale + scaleX, 0, oldPos.Y.Scale + scaleY, 0)
end
--Draggable Popup
self.Instance.InputBegan:Connect(function(input:InputObject)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsDragging = true
StartingPoint = input.Position
oldPos = self.Instance.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
IsDragging = false
end
end)
end
end)
self.Instance.InputEnded:Connect(function(input:InputObject)
if input.UserInputType == Enum.UserInputType.MouseMovement then
dragInput = input
end
end)
UIS.InputChanged:Connect(function(input)
if input == dragInput and IsDragging then
Update(self.Instance,input)
end
end)
attempt to perform arithmetic (div) on number and UDim
local UIS = game:GetService("UserInputService")
local dragFrame = script.Parent
local IsDragging = false
local StartingPoint
local oldPos
local dragInput
local function Update(uiElement, input)
local delta = input.Position - StartingPoint
local newPosition = UDim2.new(
oldPos.X.Scale, oldPos.X.Offset + delta.X,
oldPos.Y.Scale, oldPos.Y.Offset + delta.Y
)
uiElement.Position = newPosition
end
uiElement.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsDragging = true
StartingPoint = input.Position
oldPos = uiElement.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
IsDragging = false
end
end)
end
end)
uiElement.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
dragInput = input
end
end)
UIS.InputChanged:Connect(function(input)
if input == dragInput and IsDragging then
Update(uiElement, input)
end
end)
The script connects to the InputBegan
, InputEnded
, and InputChanged
events to handle the dragging behavior. The Update
function is responsible for updating the position of the UI element during dragging.
Same thing happens, it’s probably because you’re also setting the offset even though it isn’t required and can just stay 0, but i don’t know how to compensate for scale in this, if there’s no solution i’ll just scrap the dragging system
local UIS = game:GetService("UserInputService")
local self = script.Parent
local IsDragging = false
local StartingPoint
local oldPos
local dragInput
local function Update(input)
local delta = input.Position - StartingPoint
local parentSize = self.Instance.Parent.Size
local scaleX = delta.X / parentSize.X
local scaleY = delta.Y / parentSize.Y
local newPos = UDim2.new(
oldPos.X.Scale + scaleX,
oldPos.X.Offset,
oldPos.Y.Scale + scaleY,
oldPos.Y.Offset
)
self.Instance.Position = newPos
end
self.Instance.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsDragging = true
StartingPoint = input.Position
oldPos = self.Instance.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
IsDragging = false
end
end)
end
end)
self.Instance.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
dragInput = input
end
end)
UIS.InputChanged:Connect(function(input)
if input == dragInput and IsDragging then
Update(input)
end
end)
Same error, it’s because you’re trying to add Vector2 with UDim2 you have to select offset or scale