I’ll start by listing the limitations, problems, and weaknesses of this module, so you know if it’s useful to you before you bother reading this thread.
It only works for scrolling on one axis (Up/Down or Left/Right, never both at once)
It is tied to framerate, so it’ll scroll smoothly regardless of FPS. I view this as a feature, but it’s worth noting that slower devices will scroll slower.
ScrollingFrames on PC are painful to use. Scrolling on them jumps the CanvasPosition around, and they have no inertia at all.
If there’s text in a ScrollingFrame, it’s hard to read because when you scroll it jumps and you lose your place. My game (Lua Learning) is a lot of reading, so being able to scroll without losing track is a big deal. This module is designed for my case, but I’m sure many of you could use it as well.
(These GIFs are 25FPS, but the smooth version is juicy in game at 60FPS.)
I’ve seen a couple weird ways people have done it, none of them easy to just plug into your game.
One way was made out of multiple frames and required you to completely change your code, others are hard coded to a single frame, etc.
So, I wrote another open-source module!
Implementation and usage is incredibly easy. You use regular ScrollingFrames when creating your GUIs, and just tell the module to make it smooth. It does the rest!
(I used Rodocs to document the module, and I highly recommend it.)
function SmoothScroll.Enable(Frame, Sensitivity, Friction, Inverted, Axis)
Sets a ScrollingFrame to scroll smoothly
The ScrollingFrame object to apply smoothing to
How many pixels it scrolls per wheel turn
What the velocity is multiplied by each frame (Clamped between 0.2 and 0.99)
Inverts the scrolling direction
“X” or “Y”. If left out, will default to whichever Axis is scrollable or “Y” if both are valid
Sets a ScrollingFrame to scroll normally
The ScrollingFrame object to remove smoothing from
It’s super simple. It’s also coded defensively, so even if you mess up, it’ll either use default or just ‘warn’ and not smooth it. This means the module should never halt or break your code. If you find an error case that does, let me know!
local SmoothScroll = require(script.SmoothScroll) local ScreenGui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui") SmoothScroll.Enable(ScreenGui.ScrollingFrame)
I hope you guys find this as useful as I do! I’m certain that one day, Roblox will make this behavior the default. Until that day, this is what I’ll be using! I hope they also let us disable/alter the sensitivity and friction of the mobile ScrollingFrames.