Why is my frame lagging behind my arrow?

wHY IS MY FRAME LAGGING BEHIND MY ARROW when I move it?

dragger function

function dragger.new(frame)
    local s, event = pcall(function()
        return frame.MouseEnter
    end)
    if s then
        frame.Active = true
        table.insert(library.connections, event:Connect(function()
            local input = frame.InputBegan:Connect(function(key)
                if key.UserInputType == Enum.UserInputType.MouseButton1 then
                    local objectPosition = Vector2.new(mouse.X - frame.AbsolutePosition.X, mouse.Y - frame.AbsolutePosition.Y)
                    while heartbeat:wait() and inputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
                        pcall(function()
                            frame:TweenPosition(UDim2.new(0, mouse.X - objectPosition.X + (frame.Size.X.Offset * frame.AnchorPoint.X), 0, mouse.Y - objectPosition.Y + (frame.Size.Y.Offset * frame.AnchorPoint.Y)), "Out", "Linear", 0.1, true)
                        end)
                    end
                end
            end)
			table.insert(library.connections, input)
            local leave
            leave = frame.MouseLeave:Connect(function()
                input:Disconnect()
                leave:Disconnect()
            end)
			table.insert(library.connections, leave)
        end))
    end
end

It is possible that the TweenPosition function is causing issues. I’m not absolutely sure where to begin from here to resolve that.

Trivial, but certain functions are from deprecated API(which is camelCased). The pcall() demonstrates no real usage in this case and it’s only used for yielding API, which can randomly error if not careful(service breaking).

3 Likes

Tweening by nature takes time to reach the destination. If you only moved the mouse instantly to a new position it would take 0.1 seconds to get there from your Tweening function.

The frame’s delay by using heartbeat instead of renderstepped just adds to this, as the position change doesn’t result in a visual change until the subsequent frame.

If you want it to instantaneously always be bang on where the mouse is, use renderstepped and set the position directly without the tween.

4 Likes

I agree with Bantech, as I’ve had a similar click and drag function of GUI elements, in a past game I was developing that allowed you to receive restaurant orders and then drag the ticket to the “DONE” area of the screen once the order was complete, after which the customer would get their order…Directly changing the position of the GUI element according to the mouse position works well with renderstepped.

1 Like