I am making a system where you can move a frame inside of a scrollingFrame based on the mouse position.
Although I got the frame to follow the mouse position, it does not work how I want it to when I scroll.
--Code to make it follow the Mouse
local xS = ((- layersScroll.AbsolutePosition.X + mouse.X) / layersScroll.AbsoluteCanvasSize.X)
clone.Position = UDim2.new(xS,0,.5,0)
Along with minor changes in the math for xS, this is my current xS variable, which works a lot better, but still not what I want.
I know itāll have something to do with the CanvasPosition.X but I just canāt figure out what I need to do. I keep trying to divide and multiply things, but nothing has worked yet, hence why I came here.
You will need to take the scrolling position of the scrolling frame into account when calculating the position of the frame. You can do this by using the CanvasPosition property of the scrolling frame, which gives the position of the scrolling frameās content within the frame.
Example:
In this code, we use the CanvasPosition.X value to calculate a factor that is used to adjust the position of the frame. This factor is equal to 1 when the scrolling frame is scrolled all the way to the left, and decreases as the scrolling frame is scrolled to the right. This means that the frame will move more quickly when the scrolling frame is scrolled to the left, and more slowly when the scrolling frame is scrolled to the right.