Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my tween service executing only once?

local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local properties = {
	Rotation = 360
}

local rotate = tweenservice:Create(ImageButton, tweeninfo, properties)

local debounce = false

ImageButton.MouseButton1Click:Connect(function()
	if not debounce then
        debounce = true
        rotate:Play()
        wait(2)
        debounce = false
    end
end)

Can you tell me why?

2 answers

I think it's because you're pressing the button before the tween is completed and so you're debouncing it as it's playing. Tween has a Completed event that you can use to make the debounce false.

rotate.Completed:Connect(function()
	if debounce then
		denounce = false
	end
end) 

1 comment

0

let me try

It's because your property Rotation is set to 360, when first time it finishes tweening, the ui is already at 360 rotation which means it has nowhere to rotate next time, you can fix that by creating new tween every time you press the button or a better solution, setting Rotation back to 0 after the tween finished.

[...]

local rotate = tweenservice:Create(ImageButton, tweeninfo, properties)

local debounce = false

ImageButton.MouseButton1Click:Connect(function()
	if not debounce then
		debounce = true

		rotate:Play()
		rotate.Completed:Wait()
		
		ImageButton.Rotation = 0
		
		wait(2 - tweeninfo.Time)

		debounce = false
	end
end)

This will wait until the tween completes and sets the rotation back to 0. That might not be the perfect solution, but i hope you get the idea, you can replace the wait with wait(1) since tween time in this case is one second, so 2 - 1 but it's a magic number so i don't use those, it's up to you.

This discussion is preserved as it was. New answers, comments, and votes are closed.