Tweening Problem

I was doing a opening and closing button for a ui but it doesn’t work due to a error
image
Here is the Script:

local Player = game.Players.LocalPlayer
local MainFrame = Player.PlayerGui:WaitForChild("HelpButton").MainFrame


script.Parent.MouseButton1Up:Connect(function()
	if MainFrame.Visible == false then
		MainFrame.Visible = true
		MainFrame:TweenPosition(
			UDim2.new(0.394, 0, 0.338, 0),
			"Elastic",
			"Out",
			0.5,
			true
		)
	elseif MainFrame.Visible == true then
		MainFrame:TweenPosition(
			UDim2.new(0.394, 0, 1, 0),
			"Elastic",
			"Out",
			0.5,
			true
		)
		wait(0.5)
		MainFrame.Visible = false
	end
end)

Any help would be appreciated

Instead of TweenPosition, why don’t you use TweenService?

game:GetSerivce("TweenService"):Create(MainFrame, TweenInfo.new(0.5), {Position = UDim2.new(0.394, 0, 0.338, 0)}):Play() -- Snippet
--TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out, 0.5, true)
1 Like

Flip the EasingDirection and EasingStyle

"Out", -- First
"Elastic" -- Second

Also I recommend using UDim2.fromScale if you are only using the Scale

TweenPosition is TweenService but for UI’s?

It’s deprecated and much better off to use tweenservice as a whole instead.
Not to mention it has more proprieties to tween.
https://create.roblox.com/docs/reference/engine/classes/GuiObject#TweenPosition

1 Like

TweenPosition isnt Deprecated.

Either way in this Case, it will make no Difference, Those “Extra” Properties (Ex: Reversable and Delay) Are never really used either

Tweening rotation is never used in guiobjects…? Okay…
Also TweenPosition is a boolean unlike tweenservice’s animation tween where you can freely control it, such as loop it, pause it or fire a connection when it ends.

1 Like
local Player = game.Players.LocalPlayer
local MainFrame = Player.PlayerGui:WaitForChild("HelpButton").MainFrame
local TweenService = game:GetService("TweenService")

script.Parent.MouseButton1Up:Connect(function()
	if MainFrame.Visible == false then
		MainFrame.Visible = true
		TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out), {Position = Udim2.fromScale(0.394, 0.338)}):Play()
	elseif MainFrame.Visible == true then
		TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out), {Position = Udim2.fromScale(0.394,1)}):Play()
		wait(0.5)
		MainFrame.Visible = false
	end
end)

Try this out. It uses TweenService instead of the built-in TweenPosition().

Ah, Missed that one.

That’s not how that works, You are not allowed to use Strings for EasingStyle and EasingDirection with TweenService

There, replaced it with the Enum variants.

Yess that was indeed the problem…I faced this problem so many times in the past and I was able to fix it but since I wasn’t on for a while I forgot…But I did remember it’s something simple no big change in the code, Perfect answer, Thank you so much mate :slightly_smiling_face:

It’s much more work why do that instead of just doing it directly

I would use it if it’s parts or properties of stuff…But it’s ui and it’s much simpler to use tween position and I knew that wasn’t the case…But thank you for the recommendation

this is eazy plugin to create ui animation

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.