SmoothScroll Module [Superseded by Roblox Update 421]

In the module, there are a few prints commented out (Click, Drag, and two of Release)

Uncomment and see if Release gets printed

Thanks!

Nope, it doesnā€™t get printed (also I did uncomment it)

I have to go to work, but when Iā€™m free Iā€™ll look into the issue. Can you DM me your GUI? It might have to do with the layout and parenting.

Oh man, this is humiliating.
The bug was because Iā€™d used autocomplete for a variable and I bumped the wrong one.

Uploaded the updated file. Sorry about that!

1 Like

Iā€™ve now implemented this into Lua Learning (currently on front page) so Iā€™ll get lots of user feedback and bug reports on it.

I hope it works!

Edit: 4 days later, no complaints so far. It was implemented on almost every ScrollingFrame in the game, so Iā€™m taking this a confirmation of full functionality. Note that I am using the UIS edition, not the CAS. Thereā€™s no camera in my game, so thereā€™s no downside for me. Steps to change your version to the UIS edition can be found below:

1 Like

I just implemented this into my game and a few players are complaining they canā€™t scroll?

Iā€™m sorry to hear that!
Without more info, I canā€™t really help you?

My guess is that youā€™ve hit the ContextActionService sinking issue from earlier in this thread:

To avoid this, youā€™d want to replace the CAS binding with a UserInputService binding that ignores GameProcessed. Note that this means input will not be sunk, and scrolling might affect the camera.

Steps to change from CAS to UIS
  1. Remove lines 57-71:
	CAS:BindActionAtPriority("SmoothScroll", function(Name,State,Input)
		
		if DraggingBar then return Enum.ContextActionResult.Pass end
		
		local Processed = false
		for Frame, Info in pairs(Objects) do
			if Info.Hovering and Info.Visibility.Visible == true then
				Processed = true
				Info.Velocity = Info.Velocity - (Info.Sens * Input.Position.Z * (Info.Inverted and -1 or 1))
			end
		end
		
		return Processed and Enum.ContextActionResult.Sink or Enum.ContextActionResult.Pass
		
	end, false, 8000, Enum.UserInputType.MouseWheel)
  1. In that spot (from line 57) add the following:
	UIS.InputChanged:Connect(function(Input, GP)
		if --[[not GP and]] Input.UserInputType == Enum.UserInputType.MouseWheel and not DraggingBar then
			for Frame, Info in pairs(Objects) do
				if Info.Hovering and Info.Visibility.Visible == true then
					Info.Velocity = Info.Velocity - (Info.Sens * Input.Position.Z * (Info.Inverted and -1 or 1))
				end
			end
		end
	end)
1 Like

Yeah I donā€™t want it to affect the camera :confused:
I tried to use it on a scrolling frame with buttons and It didnā€™t work so I had to disable it for that specific scrolling frame.

The smooth scrolling for the other scrolling frames work fine for me, but a few players sometimes arenā€™t able to scroll for some reason??

This is awesome! Iā€™ve been using this in all of my ScrollingFrames, it is really smooth.

1 Like

Iā€™m not sure why but I seem to be receiving an ā€œinvalid frame to smoothā€ when the frame Iā€™m trying to do is a ScrollingFrame?

Oh nice! Iā€™ve used this quite a bit now and itā€™s pretty good.
Thank you for making this :slightly_smiling_face:

1 Like

Roblox has recently released an API for trackpad gestures. As seen previously in this thread, trackpad users can only scroll via the drag bar with this moduleā€™s current state. I am working on adding proper trackpad support, and will then update this thread and the model.

I have a functioning prototype.

However, it falls into the problem of CAS vs. UIS that has been discussed throughout this thread. Because the API is currently UIS-only, there is no way for me to sink the input.
Because of this, this feature may have to wait until Roblox adds trackpad support into the CAS API as well. I have asked them about this, so we shall see.

2 Likes

The module is finally completely functional!


Everyone should go replace the module with this new version if theyā€™ve been using it.

TL;DR:

  • Trackpad support
  • Fixed issues with not scrolling in some cases
  • Fixed issues with affecting camera when scrolling a frame

Everyone make sure to thank @colbert2677 for he helped me test trackpad support and he solved the UIS/CAS issue.


Previous issues

If you remember earlier in the thread, we discussed these.

If the module uses UIS to scroll, the the scrolling input does not get sunk and will move the camera+any other wheel/pan events youā€™ve connected.

If the module uses CAS to scroll, we can sink the input just fine, but the input doesnā€™t fire at all when the mouse is over an object inside the frame that can be clicked. (TextBox,ImageButton, etc)

Example of this issue from earlier in the thread

@colbert2677 discovered that the .Active property fixes the CAS issue, making it the perfect solution. Additionally, the trackpad is an exception to the UIS issue, because the new default camera script uses it too, and only goes if GP is false. The old camera script was CAS-based, so you needed the input sink for it to work. Because the new one is UIS (for trackpads, at least) we can use UIS in this case.

Current behavior

This module now behaves exactly as the default scrolling, but smoothed. It is finally exactly what Iā€™ve been trying to achieve this whole time.

When scrolling, the camera doesnā€™t get affected. Perfect. When there are GuiButtons in the frame, it still scrolls properly, including sinking the input. We did it!

When you call .Enable() on a frame, it will disable .Active on all the frameā€™s descendants (and future descendants), and store what the property was. When you call .Disable() on the frame, itā€™ll return all the descendants to their original .Active property. This ensures that CAS behaves properly, and that disabling smoothing will fully return to the original state.


Module:

Iā€™m linking it again so you wonā€™t have to scroll all the way back up.

15 Likes

The sensitivity for trackpads appears to be insane in your Lua Learning game, and frames will scroll a ridiculous amount from a tiny trackpad movement. I am using a trackpad on a MacOS if thatā€™s important. I havenā€™t yet tried Mac trackpad functionality on a scrolling frame using your module.

Edit: I think this is a bug with your game. The module works fine with my trackpad :rofl:

Thatā€™s really weird.
And annoying, since I donā€™t have a trackpad to test with.

Can you DM me more details? Which frame, etc.

Important update!

I discovered some very bad behavior: when hovering over two ScrollingFrames, both would scroll! This is obviously not ideal, as only the top should scroll.

I started doing a bunch of frustrating ancestry ZIndex tree building and sorting to figure out which is above the other.
Then I found PlayerGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y). (Wiki)
This function automatically has them sorted, with the top GUI being the first in the array.
Bonus: Itā€™s at mouse position, so I also got to remove all my hovering tracker code since anything in the array is guaranteed to be under the mouse!

Old Behavior:

(Watch the frame in the background)

New Behavior:

Module:

(Also, updated OP with example usage on how to automatically smooth every frame with exception support)

6 Likes

Update:

Improved drag bar behavior, and added support for multi-axis frames!


Old behavior:
Drag bar jumps to mouse pos, determines canvas position from mouse percent in position, only X or Y bar

old_bar

(Note how the mouse ā€œslidesā€ along the bar)

New behavior:
Determines canvas position from mouse delta, allows bar for both directions (but MouseWheel is only for Y in that case

new_bar


Module:

https://www.roblox.com/library/3507192220/SmoothScroll-Module

1 Like

Update:

Added support for ScrollingFrames inside folders!

Also, re-optimized for the new Lua VM!


I forgot that people use folders in their GUIs, so this module would just assume that .Parent was a GuiBase2d object. It now properly utilizes :FindFirstAncestorWhichIsA() in order to handle these cases.
However, the drag bar behaves differently on folder-nested frames. I cannot figure out why, since they run the same code. It still works, but it actsā€¦ slippery? It doesnā€™t stick to the mouse properly. Iā€™ll probably facepalm tomorrow and fix it.


Module:

https://www.roblox.com/library/3507192220/SmoothScroll-Module

3 Likes

Update:

Fixed 2 pretty important bugs!


  1. I think Roblox might have changed the .Active property behavior on Frames because things stopped working for a few people. Fixed it now!

  2. If you called .Disable(), it didnā€™t :Destroy() the scrollbar buttons, leaking Instances. Fixed this too!
    (Note that you shouldnā€™t ever really be calling Disable anyway since it automatically disables upon frame deletion, and toggling back and forth during the game is bad practice and wastes resources)


Module:

https://www.roblox.com/library/3507192220/SmoothScroll-Module

2 Likes

For some reason or another, this seems to cause the camera to zoom again; This used to be fixed, correct?