Trying to make a gui ability button

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? i want to make an ability button that when held down, makes the button gui smaller, and when released, makes it bigger

  2. What is the issue? Gui button tweening gets stuck if button is released too fast

  3. What solutions have you tried so far? I don’t know what my problem would be called

Hi, can you provide the code you’re using to tween the button? More than likely, your old tween is overriding your new tween when you let go of the button.

oh sorry, i thought i did,

Just to let you know for next time-- sometimes it’s hard to read code in a screen shot. Try avoiding this by formatting your code in using this button
image
First of all, you should be using TweenService and creating a new Tween instead of TweenSize because it’s deprecated.

Although, try adding another paramer to TweenSize with the value true. If it doesn’t work, let me know.
(i.e Storage.Icon:TweenSize(arg, arg, arg, arg, true)

You could use a variable and runservice to change and update the status like this.

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local MobileButtonDown = false

UIS.InputBegan:Connect(function(Input, IsTyping)
	if not IsTyping then
		if Input.KeyCode == Enum.KeyCode.C then
			MobileButtonDown = true
		end
	end
end)

UIS.InputEnded:Connect(function(Input, IsTyping)
	if not IsTyping then
		if Input.KeyCode == Enum.KeyCode.C then
			MobileButtonDown = false
		end
	end
end)

RunService.RenderStepped:Connect(function()
	if MobileButtonDown == true then
		-- code for making player sprint
	else
		-- code for making player stop sprinting
	end
end)

That’s unnecessary and would end up calling tween service more times than it should. If it’s true, it’ll continuously call tween service when it’s already finished EVERY FRAME, and vice versa.

You’re better off not using TweenSize in the first place, since TweenService overrides old tweens anyway
image
(roblox documentation)

Also, does the UI fix itself if you click the same keybind again?

Then just add a debounce to prevent it from playing the tween or just use some math that changes how the object is sized.

-- math you could use (very simple gets the job done)
IconSize += (TargetSize - IconSize) / Responsiveness -- higher values = lower responsiveness

I know the post is already solved, but you shouldn’t be creating a connection without disconnecting it inside InputBegan, which fires each time a player presses a key. Therefore, InputEnded will be connected every time the player presses a key, leading to memory leaks. Avoid this by using :Wait or :Once, or just move InputEnded:Connect outside the anonymous function.