Animation for more than one button in one script not working

This is my script, it didn’t work, at all, and gave no errors. Does anyone know how to fix it?

Script:

local tabs = game:GetService("StarterGui").Products.Menu.Dividers:GetChildren()
local tweenS = game:GetService("TweenService")
local ogSize

for i, tab in pairs(tabs) do
	if tab:IsA("TextButton") then
		tab.MouseEnter:Connect(function()
			
			ogSize = tab.Size
			local info = TweenInfo.new(
				0.5,
					Enum.EasingStyle.Elastic,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = UDim2.fromScale(tab.Size.X.Scale, 1.505)
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
		
		tab.MouseLeave:Connect(function()
			local info = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Elastic,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = ogSize
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
	end
end

ogSize is not scoped appropriately. You want ogSize to be available to the MouseLeave event, therefore, it should be scoped in the if tab:IsA("TextButton") then clause, instead of inside the connection.
Also, try using different tween settings. Personally, using Quint for the EasingStyle works almost all the time for me.
You aren’t particularly descriptive in what doesn’t work - could you elaborate?

I don’t really see how changing it to quint would work. But here is the new script, which still doesn’t work. And by “doesn’t work”, I mean it just doesn’t animate

local tabs = game:GetService(“StarterGui”).Products.Menu.Dividers:GetChildren()
local tweenS = game:GetService(“TweenService”)

for i, tab in pairs(tabs) do
	if tab:IsA("TextButton") then
		local ogSize = tab.Size
		
		tab.MouseEnter:Connect(function()
			
			local info = TweenInfo.new(
				0.5,
					Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = UDim2.fromScale(tab.Size.X.Scale, 1.505)
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
		
		tab.MouseLeave:Connect(function()
			
			local info = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = ogSize
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
	end
end

I also tried printing some stuff in various parts, and they all work properly, except for the parts with MouseEnter and MouseLeave

check out the first line, it was wrong because you would edit the startergui, not the playergui

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local playerGui = localPlayer.PlayerGui

local tabs = PlayerGui:WaitForChild("Products").Menu.Dividers:GetChildren() -- fixed this part
local tweenS = game:GetService("TweenService")
local ogSize

for i, tab in pairs(tabs) do
	if tab:IsA("TextButton") then
		tab.MouseEnter:Connect(function()
			
			ogSize = tab.Size
			local info = TweenInfo.new(
				0.5,
					Enum.EasingStyle.Elastic,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = UDim2.fromScale(tab.Size.X.Scale, 1.505)
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
		
		tab.MouseLeave:Connect(function()
			local info = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Elastic,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = ogSize
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
	end
end

[/quote]

I don’t understand what you mean. Also, I made a better script, here:

for i, tab in pairs(tabs) do
	if tab:IsA("TextButton") then
		local ogSize = tab.Size
		
		tab.MouseEnter:Connect(function()
			
			local info = TweenInfo.new(
				0.5,
					Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = UDim2.fromScale(tab.Size.X.Scale, 1.505)
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
		
		tab.MouseLeave:Connect(function()
			
			local info = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = ogSize
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
		end)
		
	end
end
  • StarterGui is not a type of Gui, it is a folder in Studio where your Guis are placed into in order for them to be put into the players when they join the game And a PlayerGui is a type of Gui that affects the individual player, not the whole server.

the script i edited for you should work with playergui

Would it work with this?

local dividers = script.Parent
local tabs = dividers:GetChildren()
local tweenS = game:GetService("TweenService")
print("e")
for i, tab in pairs(tabs) do
	print("e")

	if tab:IsA("TextButton") then
		print("e")

		local ogSize = tab.Size
		
		tab.MouseEnter:Connect(function()
			print("e")

			local info = TweenInfo.new(
				0.5,
					Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = UDim2.fromScale(tab.Size.X.Scale, 1.505)
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
			print("e")

		end)
		
		
		tab.MouseLeave:Connect(function()
			print("e")

			local info = TweenInfo.new(
				0.5,
				Enum.EasingStyle.Quint,
				Enum.EasingDirection.InOut,
				0,
				false,
				0
			)
			local goal = {
				Size = ogSize
			}
			local anim = tweenS:Create(tab, info, goal)
			anim:Play()
			print("e")

		end)
		
	end
end
1 Like

ye, no problem with it as long the parent is the ui + oops late reply