I want to move the canvas position of a scrolling frame by the click of a button, and I need help.
I was able to make the canvas move properly, but the values are the same on different devices & it will move them to somewhere else on the canvas. I want to know how to fix this issue so it goes to the right area every time. It is a struggle and I would like to hear your thoughts about this. I listed my code this problem.
local passes = script.Parent.Store.Button1
local cash = script.Parent.Store.Button2
local perks = script.Parent.Store.Button3
local TweenService = game:GetService("TweenService")
local TweenSpeed2 = 0.09
local TweenSpeed = 0.09
local TweenFunction = TweenInfo.new(TweenSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0)
local TweenFunction2 = TweenInfo.new(TweenSpeed2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0)
passes.MouseEnter:connect(function()
script.Parent.Store.ScrollingFrame.CanvasPosition = Vector2.new(0, 300)
you need to use script.Parent.Store.ScrollingFrame.CanvasPosition:TweenPosition(udim2.new(-- put your position here --), enum.easingDirection.InOut, enum.easingStyle.linear, 0.5)
CanvasPosition and CanvasSize are both output in pixels, not scale. This means that if you have it sized according to scale, the canvasSize and therefore CanvasPosition are different on different screen sizes. You can use some math to figure out what the pixel position is based on the scale.
Furthermore, 0,0 will always be the same, but 0,300 will be vastly different on a PC from on a phone. I would suggest that if your UI objects are positioned using scale, you change them from Vector2.new(0,300) to something like Vector2.new(0,CanvasPosition.Size.Y * [scale position here]).
My code may not be perfect, it’s been a while since I used scrollingFrames and I don’t have studio open to check that currently, I think that that or something similar to it should work.
Is there a way where I can make it all one line of code? I’ve tried the math and it seems I have to write a line of code for every device. Could there be a more simpler way of doing this?