When I hold the button down and release with a little delay it works fine, but when I change everything to one code with mousebutton click it wont work. My question is how would I make this script more consistent so when I click the button it plays the small → large tween
You can use the event MouseEnter and MouseLeave to detect when to set buttons size back to default. When the MouseLeave event fires you can set it to the default size. More on this here:
You should use TweenService to accomplish this goal, TweenService is a lot better for this goal as it gives you more options rather than Positioning and Sizing, you can even reverse the Tween to create a form of Click,:
ts = game.TweenService
e = script.Parent
info = TweenInfo.new( -- TweenInfo
.15,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
true
)
e.MouseButton1Down:Connect(function()
ts:Create(e, info, {Size = UDim2.new(.031, 0,.119, 0)}):Play() -- Random Size
end)
It doesn’t Require MouseButton1Up for this goal.
You Should also be using UDim2.fromScale() if you are only using the scale parameters, you can also shorten your numbers a bit, like for example, instead of 0.8, you can just do .8 and Lua will still understand it, Here is an Example of UDim2s
UDim2.new(0.522, 0, 0.277, 0) -- if you're using both scale and offset
UDim2.fromScale(.522, .277) -- works with Scale
UDim2.fromOffset(0, 0) -- works with offset
task.delay() is useless, you can easily reverse the tween with TweenService