How to scroll using scripts?

I want to make a scrolling frame but I need to disable scrolling and add two buttons, an up and down button, and when you hold on the up button the scrolling frame scrolls up and the same for down.

any way that I can do that? Also when I hold the button it doesn’t work I used script.Parent.MouseButton1Down

I’m pretty sure you can use the CanvasPosition property of ScrollingFrame instances to accomplish said task. Each time a player clicks the up or down button, tween or just change the CanvasPosition property accordingly. Have a good day.

  • MattPrograms
1 Like

But how do I make it so that you can hold the buttons and it will keep on scrolling instead of having to click alot

local Frame = script.Parent.ScrollingFrame -- Change to frame.
local UpButton = script.Parent.Up -- Change to the correct pathway in your game.
local DownButton = script.Parent.Down -- Again, change pathway.

local HoldingUp = false
local HoldingDown = false

UpButton.MouseButton1Down:Connect(function()
     HoldingUp = true
     HoldingDown = false
end)

UpButton.MouseButton1Up:Connect(function()
     HoldingUp = false
     HoldingDown = false
end)

DownButton.MouseButton1Down:Connect(function()
     HoldingDown = true
     HoldingUp = false
end)

DownButton.MouseButton1Up:Connect(function()
     HoldingDown = false
     HoldingUp = false
end)

coroutine.wrap(function()
     while wait() do
          local inc = 0
          
          if HoldingUp then
               inc = -1
          elseif HoldingDown then
               inc = 1
          end
          
          Frame.CanvasPosition = math.clamp(Frame.CanvasPosition + inc,0,Frame.AbsoluteWindowSize.Y)
     end
end)()

I haven’t tested this myself, so it might have problems. But this is just what I thought from the top of my head. Hopefully it helps. Enjoy!

no, for some reason it just doesn’t scroll

Did you define the variables? 30char

Yes I did define but for some reason nothing happens when I click and hold the buttons

You receive no errors?

random words

Nope, no errors for some reason. Only the errors from my self-made plugins…
image

local UpButton = script.Parent.Up.TextButton
local DownButton = script.Parent.Down.TextButton

local HoldingUp = false
local HoldingDown = false

UpButton.MouseButton1Down:Connect(function()
	HoldingUp = true
	HoldingDown = false
end)

UpButton.MouseButton1Up:Connect(function()
	HoldingUp = false
	HoldingDown = false
end)

DownButton.MouseButton1Down:Connect(function()
	HoldingDown = true
	HoldingUp = false
end)

DownButton.MouseButton1Up:Connect(function()
	HoldingDown = false
	HoldingUp = false
end)

coroutine.wrap(function()
	while wait() do
		local inc = 0

		if HoldingUp then
			inc = -5
		elseif HoldingDown then
			inc = 5
		end

		Frame.CanvasPosition = math.clamp(Frame.CanvasPosition + inc,0,Frame.AbsoluteWindowSize.Y)
	end
end)```

Change this line to:

Frame.CanvasPosition = math.clamp(Frame.CanvasPosition + inc,0,Frame.AbsoluteSize.Y)

I made a mistake (I think).

Here is some footage of the “new” line but still doesn’t work (my cursor became invisible because I was recording the footage so I accidently keep clicking the post button…)
https://i.gyazo.com/d30fedd79c433740345d2554b038ea47.mp4

So I think you can’t scroll because the CanvasSize is 0 maybe???

image
Wait I just changed canvas pos to 0,0

OH! It’s a UDim value. I am so sorry for the confusion.

Frame.CanvasPosition = UDim.new(0,math.clamp(Frame.CanvasPosition + inc,0,Frame.AbsoluteSize.Y))

robloxapp-20201115-1303055.wmv (771.1 KB)

Add me as a friend. I am gonna figure this out.

Lol, I just realized you were playing my game. I added you as a friend.