How would i make tween stop when button stops being holded

So i have interaction system when the player holds e the bar loads but if the player lets go off e it finishs the tween how would i make it decrease as soon as the player stops

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

for _, part in pairs(workspace.Interactions:GetChildren()) do
	local GUI = part.BillboardGui.Frame




for _, part in pairs(workspace.Interactions:GetChildren()) do
	local pos = part.Position

	UIS.InputBegan:connect(function(Input)
		local KeyCode = Input.KeyCode
		local distance = Player:DistanceFromCharacter(pos)

		if KeyCode == Enum.KeyCode.E then
			if distance <= 25 then
				warn("Played Pressed E ")
				
					GUI:TweenSize(UDim2.new(1, 0,0.1, 0), "In", "Linear", 5)

		
					
				end
				
			end
			

		end)
		
		
		UIS.InputEnded:connect(function(Input)
			GUI:TweenSize(UDim2.new(0, 0,0.9, 0), "In", "Linear", 3)
		end)
		
	end
end

You could just check if the same Input held down is the same key when you watch for your InputEnded event

		UIS.InputEnded:connect(function(Input)
            if Input.KeyCode == Enum.KeyCode.E then
		    	GUI:TweenSize(UDim2.new(0, 0,0.9, 0), "In", "Linear", 3)
            end
		end)
1 Like

The first tween still finishs even tho im not holding it

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

for _, part in pairs(workspace.Interactions:GetChildren()) do
	local GUI = part.BillboardGui.Frame




for _, part in pairs(workspace.Interactions:GetChildren()) do
	local pos = part.Position

	UIS.InputBegan:connect(function(Input)
		local KeyCode = Input.KeyCode
		local distance = Player:DistanceFromCharacter(pos)

		if KeyCode == Enum.KeyCode.E then
			if distance <= 25 then
				warn("Played Pressed E ")
				
					GUI:TweenSize(UDim2.new(1, 0,0.1, 0), "In", "Linear", 5)

					UIS.InputEnded:connect(function(Input)
						if Input.KeyCode == Enum.KeyCode.E then
							GUI:TweenSize(UDim2.new(0, 0,0.9, 0), "In", "Linear", 3)
						end
					end)
					
				end
				
			end
			

		end)
		
	end
end

You could just override the tween so that it still fires even when there’s a tween playing:

local Player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

for _, part in pairs(workspace.Interactions:GetChildren()) do
	local GUI = part.BillboardGui.Frame




for _, part in pairs(workspace.Interactions:GetChildren()) do
	local pos = part.Position

	UIS.InputBegan:connect(function(Input)
		local KeyCode = Input.KeyCode
		local distance = Player:DistanceFromCharacter(pos)

		if KeyCode == Enum.KeyCode.E then
			if distance <= 25 then
				warn("Played Pressed E ")
				
					GUI:TweenSize(UDim2.new(1, 0,0.1, 0), "In", "Linear", 5, true)

					UIS.InputEnded:connect(function(Input)
						if Input.KeyCode == Enum.KeyCode.E then
							GUI:TweenSize(UDim2.new(0, 0,0.9, 0), "In", "Linear", 3, true)
						end
					end)
					
				end
				
			end
			

		end)
		
	end
end
2 Likes