User Input doesn't work as intended

Hey, as you will see in the video and in the script below, I’ve created a tween which enables when ''Tab" key is pressed and an other one which enables when the “Tab” key is released. It works fine, however, if you just press “Tab”, without holding, only the first tween will occur. Any suggestions?

Here is the script

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local PlrUI = player:WaitForChild("PlayerGui");
local ObjectiveGui = PlrUI:WaitForChild("ObjectiveGui")
local Objective = ObjectiveGui:WaitForChild("Objective");
local Objectives = ObjectiveGui:WaitForChild("Objectives");
local TweenService = game:GetService("TweenService")
local mouse = player:GetMouse()
local Humanoid = player.Character:FindFirstChild('Humanoid')

UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if(inputObject.KeyCode == Enum.KeyCode.Tab) then
		Objective:TweenPosition(, 0, 0.025, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1)
		Objectives:TweenPosition(, 0, 0.075, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1)

UIS.InputEnded:Connect(function(inputObject, gameProcessedEvent)
	if(inputObject.KeyCode == Enum.KeyCode.Tab)then
		Objective:TweenPosition(, 0,0.025, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)
		Objectives:TweenPosition(, 0,0.075, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)

Here is the video

Λ in the first attempt I hold the Tab key and it works just perfectly.
in the second attempt I press the Tab key, and the second tween won’t happen


TweenPosition has an override parameter which defaults to false. It’s right after the time parameter.

You can try setting this to true on all tweens so that the tween will be interrupted when tab is released, although I’m not sure if it’d cause any funky behavior.


Well, you were right! :slight_smile:
Thank you so much!

1 Like