Command Bar Slide Back In When Pressing Enter

Hello! I was wondering, how do I make my command bar slide back inside when you press enter? Yes, I do have the tweening animations ready, here’s what the code looks like;

--[[

Handler.

--]]

-- Variables --

local TweenService = game:GetService("TweenService")
local CommandBarFrame = script.Parent.CommandBarFrame
local CommandBarText = script.Parent.CommandBarFrame.CommandBar
local IntroFrame = script.Parent.InfroFrame
local DismissButton = script.Parent.InfroFrame.DismissButton
local LocalPlayer = game.Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local CMDOpen = false

-- Tweens --

local CommandBarSlideOut = TweenService:Create(CommandBarFrame, TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out),{Position = UDim2.new(0, 0,0.875, 0)})
local CommandBarSlideIn = TweenService:Create(CommandBarFrame, TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.In),{Position = UDim2.new(-1, 0,0.875, 0)})

local IntroFrameSlideOut = TweenService:Create(IntroFrame, TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out),{Position = UDim2.new(0.89, 0,0.424, 0)})
local IntroFrameSlideIn = TweenService:Create(IntroFrame, TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.In),{Position = UDim2.new(1.9, 0,0.424, 0)})

-- Keys --

Mouse.KeyDown:Connect(function(Key)
	if Key == ";" and CMDOpen == false then
		CommandBarSlideOut:Play()
		CommandBarText:CaptureFocus()
		CMDOpen = true
		spawn(function()
			CommandBarText.Text = ""
		end)
	end
end)

What methods are there? I’ve tried ReleaseFocus() when you press enter with tweens which works partly, it does release the focus but doesn’t play the animation.

You can use the event TextBox.FocusLost. In your case, you can do this like so:

CommandBarText.FocusLost:Connect(function(enterPressed)
    -- Input your code here

    -- enterPressed is a boolean that tells you whether
    -- or not enter was pressed to lose focus.
end)

Edit: Make sure that CommandBarText.MultiLine is set to false, otherwise FocusLost will not fire upon an enter keypress.

1 Like

FYI: mouse.KeyDown or anything related to keys in mouse is deprecated

2 Likes