Hello there! I am trying to set a limit on my buttons position tween. I have been testing all sorts of methods on how to limit this amount through if statements, yet, I still can’t seem to make it work.
Basically, my tween positions the button properly, but the problem is that if you spam hover your mouse into the radius of the button, the tween starts to go out of place. I will provide a video below of me hovering over the button fast:
And of course, here is the script (a local script):
local button_side_effect = button_object.button_side_effect
local button_text = button_object.button_text
local tween_service = game:GetService("TweenService")
local tween_effect_time = 0.5
local move_amount = 0.05
local original_position = button_object.Position
print(original_position)
button_object.MouseEnter:Connect(function()
tween_service:Create(button_object, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
tween_service:Create(button_side_effect, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
if button_object.Position.X.Scale >= button_object.Position.X.Scale + move_amount then
print("bigger")
else
tween_service:Create(button_object, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Position = UDim2.new(button_object.Position.X.Scale + move_amount, button_object.Position.X.Offset, button_object.Position.Y.Scale, button_object.Position.Y.Offset)}):Play()
end
end)
button_object.MouseLeave:Connect(function()
tween_service:Create(button_object, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
tween_service:Create(button_side_effect, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
if button_object.Position.X.Scale >= button_object.Position.X.Scale - move_amount then
tween_service:Create(button_object, TweenInfo.new(tween_effect_time, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Position = UDim2.new(button_object.Position.X.Scale - move_amount, button_object.Position.X.Offset, button_object.Position.Y.Scale, button_object.Position.Y.Offset)}):Play()
else
print("bigger")
end
end)
Thank you in advance if the issue is solved.