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.
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:
--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.
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)