I was wondering if it is possible to scroll to a specific item on a scrolling frame by pressing a button. This means that if I press a certain button, the scrolling frame would instantly scroll to a target item. Is there a pre-made function?
You could create a tween to move to the position of the scrolling frame where the button is.
Here is how you could do it:
local CanvasPositionY = 0 --CanvasPosition Y of where the button is
local button = script.Parent --Path of the button
local ScrollingFrame = script.Parent.Parent.ScrollingFrame --Path of the scrolling frame
local TS = game:GetService("TweenService")
button.MouseButton1Click:Connect(function()
local tween = TS:Create(ScrollingFrame, TweenInfo.New(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
tween:Play()
end)
Oops, I forgot something. I needed to add the end properties.
Here is the fixed code:
local CanvasPositionY = 0 --CanvasPosition Y of where the button is
local button = script.Parent --Path of the button
local ScrollingFrame = script.Parent.Parent.ScrollingFrame --Path of the scrolling frame
local TS = game:GetService("TweenService")
button.MouseButton1Click:Connect(function()
local tween = TS:Create(ScrollingFrame.CanvasPosition, TweenInfo.New(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), { Y = CanvasPositionY })
tween:Play()
end)