Tween not stopping in collection service'd for loop

Title. It play’s just fine, won’t stop, though.

Module to start and stop:

UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.F and InvHover ~= nil and TweenHandler.isPlaying == false then
			tempInv = InvHover
			TweenHandler:StartTween()
		else
			return
		end
	end)
	
	UIS.InputBegan:Connect(function(input)
		if HBHover == nil and TweenHandler.isPlaying == true  then
			TweenHandler:StartTween()
		else
			return
		end
	end)

Receiving end:

local TweenHandler = {}

--// Variables

local CS = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

--// TweenInfo

local goalColor = Color3.fromRGB(84,255,37)
local originalColor = Color3.fromRGB(255,223,202)

TweenHandler.isPlaying = false
		
local tweenInfo = TweenInfo.new(
	.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	-1,
	true,
	0
)

local properties = {
	BackgroundColor3 = goalColor,
	Size = UDim2.new(.08,0,.734,0)
}



function TweenHandler:StartTween()
	
	for _,imageButton in player.PlayerGui.InGameUI.Hotbar:GetChildren() do
		if imageButton.Name ~= "UICorner" and imageButton.Name ~= "UIGradient" and imageButton.Name ~= "UIListLayout" and imageButton.Name ~= "UIPadding" then
			CS:AddTag(imageButton, "HBTween")
		end
	end
	
	for i,button in CS:GetTagged("HBTween") do
		local Tween = TweenService:Create(button,tweenInfo,properties)
		
		if TweenHandler.isPlaying == false then
			print("doing this")
			Tween:Play()
		elseif TweenHandler.isPlaying == true then
			print("doing this")
			Tween:Cancel()
			button.BackgroundColor3 = originalColor
		end
	end
	
	TweenHandler.isPlaying = not TweenHandler.isPlaying
end

return TweenHandler

Could be the -1 value for RepeatCount which if set to < 0 will make it repeat infinitly.

Close this pls. I had no idea that if you tweened the same property it would garbage collect and destroy the old tween. So all I did was add another module function (Stop) to tween the size and color back to its original state.

Thanks for your time

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.