local button = button or script.TextButton:Clone()
local tween_info = TweenInfo.new(
0.2,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out
)
local show = {
Size = UDim2.new(0.24, 0, 0.14, 0)
}
local reset = {
Size = UDim2.new(0.2, 0, 0.1, 0)
}
local click = {
Size = UDim2.new(0.18, 0, 0.08, 0)
}
local show_tween = tweenservice:Create(button, tween_info, show)
local reset_tween = tweenservice:Create(button, tween_info, reset)
local click_tween = tweenservice:Create(button, tween_info, click)
local hovering = false
local clicking = false
button.MouseEnter:Connect(function()
if hovering then return end
hovering = true
if clicking then return end
show_tween:Play()
end)
button.MouseLeave:Connect(function()
if not hovering then return end
hovering = false
if clicking then return end
reset_tween:Play()
end)
button.MouseButton1Down:Connect(function()
if clicking then return end
clicking = true
print("boop :D", click_tween.PlaybackState)
show_tween:Cancel()
reset_tween:Cancel()
click_tween:Play() -- doesn't play?
end)
local function Click()
if not clicking then return end
clicking = false
click_tween:Cancel()
click_tween:Pause()
if hovering then
show_tween:Play()
click_callback()
else
reset_tween:Play()
end
end
button.MouseButton1Up:Connect(Click)
mouse.Button1Up:Connect(Click)
After clicking once or twice in quick succession, the tween doesn’t want to play again.
Update: additional debugging has made my confusion even worse:
if clicking then return end
clicking = true
show_tween:Cancel()
reset_tween:Cancel()
click_tween:Play()
print(show_tween.PlaybackState, reset_tween.PlaybackState, click_tween.PlaybackState)
So first off, you don’t really need tweenservice for tweening gui’s Size or Position. There is this function :TweenSize() that works basically the same. One key difference is that you can make the tweens override in one of the parameters. What this means is that you don’t have to cancel any tweens and so, they do it automatically.
heres a really oversimplified version of ur code where I used tweensize instead
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local button = script.Parent
local ed = Enum.EasingDirection.Out -- ed, Easing Direction
local es = Enum.EasingStyle.Sine -- es, Easing Style
local t = .2 -- Time
local show = UDim2.new(0.24, 0, 0.14, 0)
local reset = UDim2.new(0.2, 0, 0.1, 0)
local click = UDim2.new(0.18, 0, 0.08, 0)
local clicking = false
button.MouseEnter:Connect(function()
if clicking then return end
button:TweenSize(show,ed,es,t,true)
end)
button.MouseLeave:Connect(function()
if clicking then return end
button:TweenSize(reset,ed,es,t,true)
end)
button.MouseButton1Down:Connect(function()
clicking = true
print("boop :D")
button:TweenSize(click,ed,es,t,true)
end)
button.MouseButton1Up:Connect(function()
clicking = false
button:TweenSize(show,ed,es,t,true)
end)