[UNSOLVED] Why is the TweenService only working for some Buttons?

I am trying to make that all Buttons will (Play) a Tween when the Mouse Enters the Buttons Diameter and the Tween will (Stop) when Mouse will Leave. But for some reason it will only Tween some of the Buttons here’s the Script –

-- Button Script
-- These all reference the Button interaction.
local Button = script.Parent.MenuFrame.Controlls
local Button = script.Parent.MenuFrame.HowToPlay
local Button = script.Parent.MenuFrame["Fan-arts"]

-- CloseButton Script
-- These all reference the Close Button interaction.
-- local CloseFrame = script.Parent.ButtonFrame
local CloseButton = script.Parent.ButtonFrame.ControllsFrame.Close
local CloseButton = script.Parent.ButtonFrame.HowToPlayFrame.Close
local CloseButton = script.Parent.ButtonFrame["Fan-artsFrame"].Close

-- These all reference the Button Tweening.
local OriginalPosA = Button.Position
local OriginalSizeA = Button.Size

local OriginalPosB = CloseButton.Position
local OriginalSizeB = CloseButton.Size

local HoverSizeA = OriginalSizeA + UDim2.new(0, 7, 0, 7)
local HoverPosA = OriginalPosA - UDim2.new(0, 2, 0, 2)

local HoverSizeB = OriginalSizeB + UDim2.new(0, 7, 0, 7)
local HoverPosB = OriginalPosB - UDim2.new(0, 2, 0, 2)

-- These all reference the Button Tweening Interaction for Enter.
Button.MouseEnter:Connect(function()
	local TweenInfoA = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenA = TweenService:Create(Button, TweenInfoA, {Size = HoverSizeA, Position = HoverPosA})
	TweenA:Play()
end)

-- These all reference the Close Button Tweening Interaction for Enter.
CloseButton.MouseEnter:Connect(function()
	local TweenInfoB = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenB = TweenService:Create(CloseButton, TweenInfoB, {Size = HoverSizeB, Position = HoverPosB})
	TweenB:Play()
end)

-- These all reference the Button Tweening Interaction for Leave.
Button.MouseLeave:Connect(function()
	local TweenInfoC = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenC = TweenService:Create(Button, TweenInfoC, {Size = OriginalSizeA, Position = OriginalPosA})
	TweenC:Play()
end)
	
-- These all reference the Close Button Tweening Interaction for Leave.
CloseButton.MouseLeave:Connect(function()
	local TweenInfoD = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenD = TweenService:Create(CloseButton, TweenInfoD, {Size = OriginalSizeB, Position = OriginalPosB})
	TweenD:Play()
end)
2 Likes

Hello!

  1. Make sure you have the TweenService variable required at the top of your code:
local TweenService = game:GetService("TweenService")
  1. You are reusing the Button and CloseButton variables for multiple buttons. This will cause only the last assigned button to work properly. Instead, you should use separate variables for each button:
local Button1 = script.Menu.ParentFrame.Controlls
local Button2 = script.Parent.MenuFrame.HowToPlay
local Button3 = script.Parent.MenuFrame["Fan-arts"]

local CloseButton1 = script.Parent.ButtonFrame.ControllsFrame.Close
local CloseButton2 = script.Parent.ButtonFrame.HowToPlayFrame.Close
local CloseButton3 = script.Parent.ButtonFrame["Fan-artsFrame"].Close
  1. Update the references to the button variables in the Tweening interactions:
Button1.MouseEnter:Connect(function()
    local TweenInfoA = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
    local TweenA = TweenService:Create(Button1, TweenInfoA, {Size = HoverSizeA, Position = HoverPosA})
    TweenA:Play()
end)

CloseButton1.MouseEnter:Connect(function()
    local TweenInfoB = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
    local TweenB = TweenService:Create(CloseButton1, TweenInfoB, {Size = HoverSizeB, Position = HoverPosB})
    TweenB:Play()
end)

Button1.MouseLeave:Connect(function()
    local TweenInfoC = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
    local TweenC = TweenService:Create(Button1, TweenInfoC, {Size = OriginalSizeA, Position = OriginalPosA})
    TweenC:Play()
end)

CloseButton1.MouseLeave:Connect(function()
    local TweenInfoD = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
    local TweenD = TweenService:Create(CloseButton1, TweenInfoD, {Size = OriginalSizeB, Position = OriginalPosB})
    TweenD:Play()
end)

Repeat the above changes for the other buttons and close buttons

I hope all of these infos will help you:)

1 Like

you’re missing half of the Script, and Yes I have added “TweenService” at the very top of the Script.

1 Like

i was on rush,that s why i didn’t even see the rest of the code

1 Like
-- CloseButton Script
-- These all reference the Close Button interaction.
-- local CloseFrame = script.Parent.ButtonFrame
local CloseButton = script.Parent.ButtonFrame
local CloseButtonA = CloseButton.ControllsFrame.Close
local CloseButtonB = CloseButton.HowToPlayFrame.Close
local CloseButtonC = CloseButton["Fan-artsFrame"].Close

-- These all reference the Button Tweening.
local OriginalPosA = ButtonA.Position
local OriginalSizeA = ButtonA.Size
local OriginalPosB = ButtonB.Position
local OriginalSizeB = ButtonB.Size
local OriginalPosC = ButtonC.Position
local OriginalSizeC = ButtonC.Size

local OriginalPosD = CloseButtonA.Position
local OriginalSizeD = CloseButtonA.Size
local OriginalPosE = CloseButtonB.Position
local OriginalSizeE = CloseButtonB.Size
local OriginalPosF= CloseButtonC.Position
local OriginalSizeF = CloseButtonC.Size

local HoverSizeA = OriginalSizeA + OriginalSizeB + OriginalSizeC - UDim2.new(0, 7, 0, 7)
local HoverPosA = OriginalPosA + OriginalPosB + OriginalPosC - UDim2.new(0, 2, 0, 2)

local HoverSizeB = OriginalSizeD + OriginalSizeE + OriginalSizeF - UDim2.new(0, 7, 0, 7)
local HoverPosB = OriginalPosD + OriginalPosE + OriginalPosF - UDim2.new(0, 2, 0, 2)

-- These all reference the Button Tweening Interaction for Enter.
Button.MouseEnter:Connect(function()
	local TweenInfoA = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenA = TweenService:Create(ButtonA, ButtonB, ButtonC, TweenInfoA, {Size = HoverSizeA, Position = HoverPosA})
	TweenA:Play()
end)

-- These all reference the Close Button Tweening Interaction for Enter.
CloseButton.MouseEnter:Connect(function()
	local TweenInfoB = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenB = TweenService:Create(CloseButtonA, CloseButtonB, CloseButtonC, TweenInfoB, {Size = HoverSizeB, Position = HoverPosB})
	TweenB:Play()
end)

-- These all reference the Button Tweening Interaction for Leave.
Button.MouseLeave:Connect(function()
	local TweenInfoC = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenC = TweenService:Create(ButtonA, ButtonB, ButtonC, TweenInfoC, {Size = OriginalSizeA, Position = OriginalPosA})
	TweenC:Play()
end)

-- These all reference the Close Button Tweening Interaction for Leave.
CloseButton.MouseLeave:Connect(function()
	local TweenInfoD = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local TweenD = TweenService:Create(CloseButtonA, CloseButtonB, CloseButtonC, TweenInfoD, {Size = OriginalSizeB, Position = OriginalPosB})
	TweenD:Play()
end)
1 Like

*Updated Version

Max Characters

1 Like

Do I need to create a Table to represent all the Variables for the Button interference?

1 Like

You are trying to pass multiple instances, but you can only pass one. Use multiple tweens via a loop or just manually type many.

Example with a bit of bad code:

	for _, button in {ButtonA, ButtonB, ButtonC} do
		local Tween = TweenService:Create(button, TweenInfoA, {Size = HoverSizeA, Position = HoverPosA})
		Tween:Play()
	end

For more information about TweenService read the documentation: TweenService | Documentation - Roblox Creator Hub

1 Like

The TweenService implementa but it doesn’t finalize the full function.

-- CloseButton Script
-- These all reference the Close Button interaction.
-- local CloseFrame = script.Parent.ButtonFrame
local CloseButton = script.Parent.ButtonFrame
local CloseButtonA = CloseButton.ControllsFrame.Close
local CloseButtonB = CloseButton.HowToPlayFrame.Close
local CloseButtonC = CloseButton["Fan-artsFrame"].Close

-- These all reference the Button Tweening.
local OriginalPosA = ButtonA.Position
local OriginalSizeA = ButtonA.Size
local OriginalPosB = ButtonB.Position
local OriginalSizeB = ButtonB.Size
local OriginalPosC = ButtonC.Position
local OriginalSizeC = ButtonC.Size

local OriginalPosD = CloseButtonA.Position
local OriginalSizeD = CloseButtonA.Size
local OriginalPosE = CloseButtonB.Position
local OriginalSizeE = CloseButtonB.Size
local OriginalPosF= CloseButtonC.Position
local OriginalSizeF = CloseButtonC.Size

local HoverSizeA = OriginalSizeA + OriginalSizeB + OriginalSizeC - UDim2.new(0, 7, 0, 7)
local HoverPosA = OriginalPosA + OriginalPosB + OriginalPosC - UDim2.new(0, 2, 0, 2)

local HoverSizeB = OriginalSizeD + OriginalSizeE + OriginalSizeF - UDim2.new(0, 7, 0, 7)
local HoverPosB = OriginalPosD + OriginalPosE + OriginalPosF - UDim2.new(0, 2, 0, 2)

-- These all reference the Button Tweening Interaction for Enter.
Button.MouseEnter:Connect(function()
	local TweenInfoA = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	for _,Button in {ButtonA, ButtonB, ButtonC} do
		local Tween = TweenService:Create(Button, TweenInfoA, {Size = HoverSizeA, Position = HoverPosA})
		Tween:Play()
	end
end)

-- These all reference the Close Button Tweening Interaction for Enter.
CloseButton.MouseEnter:Connect(function()
	local TweenInfoB = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	for _, button in {ButtonA, ButtonB, ButtonC} do
		local Tween = TweenService:Create(CloseButton, TweenInfoB, {Size = HoverSizeA, Position = HoverPosA})
		Tween:Play()
	end
end)

-- These all reference the Button Tweening Interaction for Leave.
Button.MouseLeave:Connect(function()
	local TweenInfoC = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	for _, button in {ButtonA, ButtonB, ButtonC} do
		local Tween = TweenService:Create(Button, TweenInfoC, {Size = HoverSizeA, Position = HoverPosA})
		Tween:Play()
	end
end)

-- These all reference the Close Button Tweening Interaction for Leave.
CloseButton.MouseLeave:Connect(function()
	local TweenInfoD = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	for _, button in {ButtonA, ButtonB, ButtonC} do
		local Tween = TweenService:Create(CloseButton, TweenInfoD, {Size = HoverSizeA, Position = HoverPosA})
		Tween:Play()
	end
end)

Would anyone have any decent idea on how I can achieve this.

@ZerroxShiot Your suggestion isn’t working. I have tweaked the code so it suits my benefit but still doesn’t work to how it must. I will consider sending you a Kit containing the full Script so you can edit the Script, because I am struggling.