Seems to be working fine for me, or you could use until loops as suggested.
code:
local frame = script.Parent
local TweenService = game:GetService("TweenService")
local framepos = frame.Position
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(frame, tweenInfo, {Position = framepos + UDim2.new(0,0,0.05,0)})
tween:Play()
function onclick()
tween:Cancel()
--code here
end
script.Parent.MouseButton1Click:connect(onclick)