Button animations with 1 script?

I know how to make button animations with :TweenSize but is it possible to add button aminations with 1 script?

3 Likes

Can you elaborate a lil bit more.

I tired making a script to add animations when you hover over a button but doesn’t seem to work:

local plr = game.Players.LocalPlayer
for _, v in pairs(plr.PlayerGui.MainGUI:GetDescendants()) do
	if v:IsA("TextButton") or v:IsA("ImageButton") then
		v.MouseEnter:Connect(function()
			local newSize1 = UDim2.new(v.Size.X.Scale * 1.1, v.Size.X.Offset, v.Size.Y.Scale * 1.1, v.Size.Y.Offset)
			v:TweenSize(newSize1, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
		end)

		v.MouseLeave:Connect(function()
			local newSize2 = UDim2.new(v.Size.X.Scale / 1.1, v.Size.X.Offset, v.Size.Y.Scale / 1.1, v.Size.Y.Offset)
			v:TweenSize(newSize2, Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.25, true)
		end)
	end
end

This is the effect I want:
image
(Enlarged when hover and back to normal when unhover)

1 Like

Are you getting any errors in output?

1 Like

This may help Need Help with UI - #4 by KiloTheDev

Unfortunately not, how would that help?

try putting scripts for each button

1 Like

Please read the title, I an trying to do it with 1 script so its less repetitive and I’m going to have lots a buttons.

Do you have any advise on how to fix it?

oh well, so you’re trying to get the size by getting the scaling of v? why not like mess around with the button size and determine the size you want

1 Like

I don’t understand, what do you mean?

Really?? Yeah I’m using a UIListLayout and here’s the directory’s:
image
(just deleted the UIListLayout and still not working)

1 Like

Try doing this with a normal textbutton. if it works then it might be something in your buttons properties or uiaspectratio

Where did you put the script at?

I put the script under the textbutton

2 Likes

Ohhh I put in the StarterPlayerScripts and didnt work but then I put it in StarterGUI and worked!! Thanks!!

1 Like
local ButtonTemplate = script.ButtonTemplate
local AnimationList = script.Parent.AnimationList

local LocalPlayer = game:GetService('Players').LocalPlayer

for i,v in AnimationsModule do
      local Clone = ButtonTemplate:Clone()
      Clone.Parent = AnimationList
      Clone.Text = v.AnimationName
      Clone.MouseButton1Click:Connect(function()
            local currentChar = LocalPlayer.Character
            local Humanoid = currentChar.Humanoid
            local Animator = Humanoid.Animator

            local Animation = Instance.new('Animation')
            Animation.AnimationId = v.AnimationAssetId
            -- other properties should be put here, like looped and etc

            local AnimationTrack = Animator:LoadAnimation(Animation)
            AnimationTrack:Play()
      end)
end

Module looking:

return {
      {
            AnimationName = 'Sit';
            AnimationAssetId = 'rbxassetid://0';
      };
}
1 Like

mb, i understand wrong btw, good luck!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.