Button disappears when tweening

Hello everyone, yet again another issue has arrived.

Why is the image button glitching like this?

https://drive.google.com/file/d/1gkaQBpr6eTTzDB3jBvBX_xP9k1tYy6gb/view?usp=sharing

The script:

local Button1 = script.Parent.Defense -- I'm programming this button so far
local Button2 = script.Parent.Buildings
local Button3 = script.Parent.Traps
local Button4 = script.Parent.Robux -- lol, it aint giving bobux
local Desc = script.Parent.Desc
local Debounce = false
local SizeGoal = UDim2.new(0,170,0,140)
local SizeReturn = UDim2.new(0,150,0,120)

Button1.MouseEnter:Connect(function()
	if not Debounce then
		Debounce = true
		Button1:TweenSizeAndPosition(SizeGoal,UDim2.new(0.088,0,0.133,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Cubic,1,false)
		Desc.Text = "Cannon's, Archer tower's, etc"
		wait(.1)
		Debounce = false
	end
end)

Button1.MouseLeave:Connect(function()
	if not Debounce then
		Debounce = true
		Button1:TweenSizeAndPosition(SizeReturn,UDim2.new(0.089,0,0.15,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Cubic,1,false)
		Desc.Text = ""
		wait(.1)
		Debounce = false
	end
end)

I’m not sure what’s going on here, but I’ve tried using other guis like a text buttons image labels. The variables are correctly assigned to each button, and I’m pretty sure the variables are set correctly in the :TweenSizeAndPosition. I’ve tried tweening each property separately too (:TweenPosition :TweenSize) but its still glitching. And I’m debouncing the script too. The buttons are inside a frame though, but I don’t think that could be the issue. What going on here?

2 Likes

It could be because you have one of the parameters missing

https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenSizeAndPosition

I only see one udim2. on your goals/return, there should be two

regardless using tweensizeandposition (or equivalent) is not good, Consider setting up tweens using tween service:

2 Likes

Naa, there two UDim2.new() for each :TweenSizeAndPosition One is SizeGoal or SizeReturn and the other is inside the tween itself.

PS: Tween service does not apply to gui’s, you have to use :TweenPosition(), :TweenSize() or :TweenSizeAndPosition() to make a Gui move.

2 Likes

you should put that bool (the last one in the parameter) to true

1 Like

The bool parameter deals with overriding other tweens, it doesn’t stop a tween or make it glitch out.
I tried it anyway, but still didn’t work :sad:

1 Like

You’re wrong, tween service is for anything involving what the api specifies

Note that only specific types of properties can be used with TweenService , but multiple properties can be animated in the same tween. The types of properties that can be tweened are:

  • number
  • bool
  • CFrame
  • Rect
  • Color3
  • UDim
  • UDim2
  • Vector2
  • Vector2int16
  • Vector3

I assume you didn’t even look at the link I provided (my forum post, not tweenservice api) which had an effective example for gui related tweens

1 Like

I did…

I’m trying to tween a gui, and I cannot call a tween service to move a gui or change it’s numbers, because it doesn’t move in the end. Which is why I have to use :TweenPosition or :TweenSize or :TweenSizeAndPosition to get it to move.

But, i’m gonna try it anyway, so I’ll change a UDim2.new() with tween service but I’m not exactly sure it’ll work.

1 Like

After testing the script for a bit, I found out why it’s broken (atleast, this worked for me): Try setting the Enum.EasingStyle to Quint instead of Cubic in your original script.

2 Likes

Right then, I get that once I’m done testing @Juicy_Fruit 's idea

2 Likes
--local tweenservice for later creation
local TweenService=game:GetService("TweenService")
local SizeandPositionGoal = {Position=UDim2.new(0.088,0,0.133,0), Size = Udim2.new(0,170,0,140)}
local SizeandPositionReturnGoal = {Position=UDim2.new(0.089,0,0.15,0), Size = Udim2.new(0,150,0,120)}
local tweenInfo = TweenInfo.new(
	1, -- Time
	Enum.EasingStyle.Cubic, -- EasingStyle
	Enum.EasingDirection.InOut, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses
	0 -- DelayTime
)
local GoTween = TweenService:Create(Button1, tweenInfo, SizeandPositionGoal )
local ReturnTween = TweenService:Create(Button1, tweenInfo, SizeandPositionReturnGoal )

Then inside mousebutton stuff do:

Button1.MouseEnter:Connect(function()
	    GoTween:Play()
		Desc.Text = "Cannon's, Archer tower's, etc"


end)

Button1.MouseLeave:Connect(function()
	        ReturnTween:Play()
		Desc.Text = ""
		
end)

3 Likes

Yes, weird that I can now tween gui’s with Tween service, couldn’t do that 9 months ago :thinking:
Anyway this is a valid solution, but @indefiniteOptimist gave a simpler solution, which is don’t use Cubic, LOL. Anyway thx for the help. :slightly_smiling_face:

1 Like

Yeah, I have no idea why that doesn’t work. I tested with Exponential too and that didn’t work either, so if it happens again just try to switch the EasingStyle.

2 Likes

Yeah every tween style should work for gui’s too… What about reporting this bug to roblox, I can’t do it since I’m just a we little member on the site.

2 Likes

I’m also a pretty tiny member on the site so I can’t sadly, but hopefully they pick up on it and fix it (assuming there is a problem with studio and not the code).

2 Likes

No don’t worry, the code isn’t the issue, since I’ve written loads script with this same code, it’s a new bug, lol

2 Likes

it is a bug, but they suggest using tweenservice to use cubic easing style until it gets fixed for the functions like tweensize position etc., which may be a long time.

2 Likes