Tweening GUI Bug

I want to make it to when you join the game and press a key the GUI tweens away and then if you press it again it tweens back Instantly.

The issue is it works but it takes about 5 or more tries in order to get it working then it bugs again and it shouldn’t be like that. I’ve tried adding a wait function but nothing changed.

(I was pressing left ctrl like 10 times before it worked.)

Here’s the code I used:

local Opened = false

local PositionClosed = UDim2.new(1, 0, 0.96, 0)
local PositionOpened = UDim2.new(0.868, 0, 0.96, 0)

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Keycode)
	if Keycode.KeyCode == Enum.KeyCode.LeftControl then
		if Opened then
			MainFrame:TweenPosition((PositionClosed), "InOut", "Quint")
			Opened = false
		else
			MainFrame:TweenPosition((PositionOpened), "InOut", "Quart")
			Opened = true
		end
	end
end)

Please let me know if there’s anything to fix this issue. Thank you.

This is a thing I notice with a lot of people.

MainFrame:TweenPosition((PositionClosed), "InOut", "Quint")

consider swapping to tweenservice instead of using tweenpos, tweensize, etc., if you swap to tweenservice, your issue will go away (cause your code is spot on and has the proper condition for open and not opened).

Here is my comment where I go about showing how to use tweenservice on a seperate thread:

I’ll look into it. Thank you, I’ll let you know if it goes right.

kind of stuck. confused rather.

stuck with what? details required

--local tweenservice for later creation
local TweenService=game:GetService("TweenService")
local goal = {Position=UDim2.new(1, 0, 0.96, 0)}

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Keycode)
	if Keycode.KeyCode == Enum.KeyCode.LeftControl then

local tweenInfo = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.InOut, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses
	0 -- DelayTime
)


That was one of my first times working with tweening UI so this is where I’m stuck.

@pradatrades

local TweenService=game:GetService("TweenService")
local Opened = false

local PositionClosed = {Position = UDim2.new(1, 0, 0.96, 0)}
local PositionOpened = {Position = UDim2.new(0.868, 0, 0.96, 0)}

local tweenInfoOpen = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.Quint, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses
	0 -- DelayTime
)

local tweenInfoClosed = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.Quart, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses
	0 -- DelayTime
)

local Opentween = TweenService:Create(MainFrame, tweenInfoOpen, PositionOpened )

local Closetween = TweenService:Create(MainFrame, tweenInfoClosed, PositionClosed)

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Keycode)
	if Keycode.KeyCode == Enum.KeyCode.LeftControl then
		if Opened then
			Opentween:Play()
			Opened = false
		else
			Closetween:Play()
			Opened = true
		end
	end
end)

EDIT: forgot to add position to goals.

ok trying it now I’ll let you know

“TweenService:Create failed because Instance is null”

where is MainFrame declared in your script?

also use this script added yet another edit:

should I rename my frame “MainFrame” because I tried that and It didn’t work.

You shouldn’t need to rename–instead somewhere near top:

(idk where its located this is just a sample)

local MainFrame = script.Parent

you might also need to :WaitForChild()

Apparently somethings up with these lines because whenever I press the error it starts me off here

local Opentween = TweenService:Create(MainFrame, tweenInfoOpen, PositionOpened )

local Closetween = TweenService:Create(MainFrame, tweenInfoClosed, PositionClosed)

can you show me the hierarchy of objects and show where MainFrame is located?


which gui object is the “mainframe” i do not see it

if its “Taunt” then just put

local MainFrame = script.Parent 

at the top of script

1 Like

Taunt is the MainFrame. For me to test this, im adding a local script for the others after . but for now Taunt is the one im working with

Oh thank you so much! It works, after this ill study more about tweening UI. Thanks for helping me out with this issue. :grinning_face_with_smiling_eyes:

1 Like