How to use the scrolling frame as Draggable?

Well I want to make a scrolling frame draggable without the Draggable feature to move the frames without using scrolling or clicking the scroll button of the ScrollingFrame.

In the following video is the Draggable function, but I want to change it to something similar in ScrollingFrame.

robloxapp-20210424-2309421.wmv (614.8 KB)

2 Likes

Is there any reason for your method to not work on a ScrollingFrame?

No, I mean I want to make the scrolling of the ScrollingFrame usable as Draggable.
Edit: What I want to do is that it can be moved from the Frame of the ScrollingFrame using the Scrolling like the Draggable, but I don’t know how to do it.

So basically you want to be able to drag the mouse to scroll instead of using the scroll wheel?

Sure enough, I know there is a scroll frame button on the right edge, but I just want the mouse to drag.

local UIS = game:GetService("UserInputService")
local scrollingFrame = script.Parent

local initPos = nil
local scrollSens = 1

scrollingFrame.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		initPos = input.Position
	end
end)

scrollingFrame.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		if not initPos then return end
		if not UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then return end
		local yChange = input.Position.Y - initPos.Y
		scrollingFrame.CanvasPosition = scrollingFrame.CanvasPosition + Vector2.new(0,yChange * scrollSens)
		initPos = input.Position
	end
end)

Try this in a localscript under the scrolling frame. You can increase the scrollSens variable for sensitivity.

It is partly a solution, but it is missing the Position.XY, but still, thanks.

What do you mean by Position.XY?

Well, I may have been wrong on the XY, but what I mean is move if horizontally and vertically with the mouse.

This will work only for vertical scrolling. Do you need it to be horizontal?

1 Like

Well, I meant that I wanted it to look like the first video on the following page: ScrollingFrame | Roblox Creator Documentation

local UIS = game:GetService("UserInputService")
local scrollingFrame = script.Parent

local initPos = nil
local scrollSens = 1.3

scrollingFrame.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		initPos = input.Position
	end
end)

scrollingFrame.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		if not initPos then return end
		if not UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then return end
		local yChange = input.Position.Y - initPos.Y
		local xChange = input.Position.X - initPos.X
		scrollingFrame.CanvasPosition = scrollingFrame.CanvasPosition + Vector2.new(xChange * scrollSens ,yChange * scrollSens)
		initPos = input.Position
	end
end)

Try this.

9 Likes

Thank you very much, you are a god!

No problem! Glad I could help.

1 Like

How can i make this work on a surface gui?