Ah I was unaware of the implications that using -1 for had in relation to the Completed event (and I had originally thought that the Completed event would fire before the Tween replays, but I was mistaken).
Potential Solution
While I havenāt dealt with this kind of situation in the past, thereās the potential that the āmagnitudeā of the GuiObjectās Size property could be utilized to determine when the Tween has gone back to its original position.
Take note that this is just a proof of concept and it could be further optimized.
local tweenLoopCount = 0 -- Amount of times the Tween has looped
local endOfTween = false -- "false" if the tweenLoopCount has not been increased on this current iteration, "true" if the opposite
local originalSize = UDim2.new(0.1, 0, 0.1, 0) -- The original Size of the GuiObject is stored here to compare with its current Size in order to determine the "magnitude"
while true do
wait()
local magnitudeCheck = (Item.Size.X.Scale - originalSize.X.Scale) -- Finds the difference between its current size on the X axis & its original size on the X axis. The Y Axis could be included, if needed
if magnitudeCheck <= 0.4 and not endOfTween then -- If the X axis's size is less than 0.4 (provides some leeway due to the duration of the tween) and the tweenLoopCount has not been increased yet, then...
endOfTween = true -- Adjusts the variable to true so the tweenLoopCount is not increased on the same iteration
tweenLoopCount += 1
warn("The tween has looped "..tweenLoopCount.." time(s)!")
elseif magnitudeCheck >= 0.6 and endOfTween then -- If the X axis's size is greater than 0.6, we know that the Tween is almost complete...
endOfTween = false -- Adjusts the variable back to false so the next iteration is able to have the tweenLoopCount increased
print("The tween is restarting")
end
end
Alternatively, instead of a āmagnitudeā check, the GuiObjectās current size could simply be compared to determine if it has exceeded a certain value rather than determining how much it has changed from its original size:
local currentSize = Item.Size.X.Scale
-- Checks if its current size is less than or equal to 0.4
if currentSize <= 0.4 and not endOfTween then
endOfTween = true
tweenLoopCount += 1
warn("The tween has looped "..tweenLoopCount.." time(s)!")
-- Checks if its current size is greater than or equal to 0.6
elseif currentSize >= 0.6 and endOfTween then
endOfTween = false
print("The tween is restarting")
end