How to refresh a function more often?

Hi, everyone! I would like to understand how am I supposed to make a function refreshing all the time.

  1. What do I want to achieve?
    I want the CanvasPosition of a ScrollingFrame not to be able to reach the origin. As well, when the CanvasPosition is inferior than 50, I reset it to 50 so it never can reach a lower value than 50.

  2. What is the issue?
    My script works but the function isn’t enough reactive. I don’t want the scrolling frame to look laggy as it currently look like though.

  3. What solutions have I tried so far?
    I’ve tried with a while wait(0.0001) do loop so it is repeated as fast as possible. Then, I went to the DevForum and I found the game:GetService("RunService").Heartbeat:Connect(function()) way to do it, but sadly, same result occured.
    Do you have any idea to solve my problem?

Here is my LocalScript content:

game:GetService("RunService").Heartbeat:Connect(function()
	if script.Parent.CanvasPosition.Y < 50 then
		script.Parent.CanvasPosition = Vector2.new(0, 50)
	end 
end)

And here is a video of what it looks:

I just want the function to happen as smooth as possible, so player don’t consider it as a bug or something of this type.

Thanks a lot by advance!

Perhaps try lerping the Vector2 values?

To implement it, simply do the following:

game:GetService("RunService").Heartbeat:Connect(function()
	if script.Parent.CanvasPosition.Y < 50 then
		script.Parent.CanvasPosition = script.Parent.CanvasPosition:Lerp(Vector2.new(0, 50), 0.5)
	end 
end)

I sadly got the same result using your program…