Trying to make a scrolling gui

I want to create a script that makes a frame scroll by MouseWheelForward & MouseWheelBackwards, this frame that’s suppose to scroll is gonna determine the lighting and other stuff like that, a scrolling thing for settings basically. This is what i currently have:

local Player = game.Players.LocalPlayer
local FrameToDrag = script.Parent
FrameToDrag.Parent.MouseEnter:Connect(function()
FrameToDrag.MouseWheelForward:Connect(function()
FrameToDrag.Position += UDim2.new(FrameToDrag.Position.X.Scale + .1, 0, -.375, 0)
end)
end)
FrameToDrag.Parent.MouseLeave:Connect(function()
FrameToDrag.MouseWheelBackward:Connect(function()
FrameToDrag.Position -= UDim2.new(FrameToDrag.Position.X.Scale - .1, 0, -.375, 0)
end)
end)

Screenshot 2022-10-31 151930

This should be in #help-and-feedback:scripting-support.

So here is your code:

FrameToDrag.Parent.MouseEnter:Connect(function()
    FrameToDrag.MouseWheelForward:Connect(function()
        FrameToDrag.Position += UDim2.new(FrameToDrag.Position.X.Scale + .1, 0, -.375, 0)
    end)
end)

FrameToDrag.Parent.MouseLeave:Connect(function()
    FrameToDrag.MouseWheelBackward:Connect(function()
        FrameToDrag.Position -= UDim2.new(FrameToDrag.Position.X.Scale - .1, 0, -.375, 0)
    end)
end)

You should never connect events inside of events, it always leads to memory leaks. Just remove the usage of MouseEnter and MouseLeave, and this script should work good enough.

it doesn’t move very well; the Y position keeps moving although i have it as 0 in both functions

Actually, you don’t. You’re moving it up and down by -0.375 scale. If you just change that to 0, then it should not move on the Y axis. Also remove FrameToDrag.Position.X.Scale in the UDim2.new’s, and then the slider should work fine.

FrameToDrag.MouseWheelForward:Connect(function()
    FrameToDrag.Position += UDim2.new(0.1)
    if FrameToDrag.Position.X.Scale < 0 then -- clamp position left
        FrameToDrag.Position -= UDim2.new(FrameToDrag.Position.X.Scale)
    end
end)

FrameToDrag.MouseWheelBackward:Connect(function()
    FrameToDrag.Position += UDim2.new(-0.1)
    if FrameToDrag.Position.X.Scale > 1 then -- clamp position right
        FrameToDrag.Position -= UDim2.new(FrameToDrag.Position.X.Scale - 1)
    end
end)