0

# How Can I Change the CanvasPosition with a TextButton?

Asked by 14 days ago

Ive used some code I wrote and It doesn't seem to work, can anybody help me out?

heres my non-working code incase you are wondering: script.Parent.MouseButton1Click:Connect(function() script.Parent.Store.ScrollingFrame.CanvasPosition:TweenPosition(UDim2.new(0, 0), Enum.easingDirection.InOut, Enum.easingStyle.linear, 0.5) end)

0
Answered by 14 days ago

[PLEASE MARK THIS ANSWER AS ACCEPTED IF IT WORKS]

To tween canvas position, you do not use :TweenPosition(), instead you tween it like you would with any other Vector2 property.

script.Parent.MouseButton1Click:Connect(function()
local TweenService = game:GetService("TweenService")

local scrollingframe = script.Parent.Store.ScrollingFrame

local goal = {}
goal.CanvasPosition = Vector2.new(0, 0)

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local tween = TweenService:Create(scrollingframe, tweenInfo, goal)

tween:Play()
end)

0
Thanks for your reply! I've tested it out and it does not seem to work, it says in the properties that the position changes, but the screen itself does not change? Guest_99866 7 — 14d
0
I would refrain from calling the service in your event. This is inefficient and it can be called upon from outside of the click event. namespace25 594 — 14d
0
Answered by 14 days ago

You don't use UDim for CanvasPosition or TweenPosition. To achieve the same result you will want to use TweenService.

For example, to move the canvas down you would do this:

local tweenService = game:GetService("TweenService")
local canvas = script.Parent.Store.ScrollingFrame

script.Parent.MouseButton1Click:Connect(function()
tweenService:Create(
canvas,
TweenInfo.new(0.2),
{CanvasPosition = canvas.CanvasPosition + Vector2.new(0, 20)}
):Play()
end)

0
It still seems to not work, ROBLOX Studio is telling me there are no errors with the script but I click the button and it does not work. Guest_99866 7 — 14d
0
Then your implementation is wrong, I tested this code in the provided set up before posting it. It may depend on how large your canvas is too so you could change the 20 to something higher. namespace25 594 — 14d