Interactive Buttons

I’m just using a LocalScript to make all of my buttons interactive and feel nicer,
but I can’t seem to fix the scaling issue. Whenever the tweens are triggered, the buttons slowly tween size into nothing.

local players = game:GetService("Players")
local tweenservice = game:GetService("TweenService")
local replicatedstorage = game:GetService("ReplicatedStorage")

local localplayer = players.LocalPlayer
local char = localplayer.Character or localplayer.CharacterAdded:Wait()

local buttondowncolor = Color3.fromRGB(177,177,177)
local buttonupcolor = Color3.fromRGB(255,255,255)

function buttonize(button: ImageButton)
	
	button.AutoButtonColor = false
	
	button.ImageColor3 = buttonupcolor
	
	local tweensize1 = tweenservice:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = UDim2.new(button.Size.X.Scale/2,button.Size.Y.Scale/2)})
	local tweensize2 = tweenservice:Create(button, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = UDim2.new(button.Size.X.Scale/2,button.Size.Y.Scale/2)})
	
	button.MouseEnter:Connect(function()
		button.ImageColor3 = buttondowncolor
		tweensize1:Play()
		print("MouseEnter")
	end)
	button.MouseLeave:Connect(function()
		button.ImageColor3 = buttonupcolor
		tweensize2:Play()
		print("MouseLeave")
	end)
	button.MouseButton1Down:Connect(function()
		button.ImageColor3 = buttondowncolor
	end)
	button.MouseButton1Up:Connect(function()
		button.ImageColor3 = buttonupcolor
	end)
	
end

for _, button in pairs(script.Parent:GetDescendants()) do
	if button:IsA("ImageButton") then
		buttonize(button)
	end
end

This should be simple, but I can’t find the solution.

When defining the new Size in the tweens, you defined X Scale as it should be, but Y Scale is defined as XOffset. Was it on purpose?

I’m confused. Where did I define the Y Scale as X Offset?

There are 4 values. xScale, xOffset, yScale and yOffset. In tweensize1 and tweensize2, you put yScale in the place of xOffset and left the other 2 values unused.

Ah, I forgot about those. Thank you for your help!

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