Is it possible to check when a tween is halfway done?

  1. What do you want to achieve? Keep it simple and clear! “I feel like the title already kind of answered that question.”

  2. What is the issue? Include screenshots / videos if possible! “I dont really know how i would do that.”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? “I’ve tried using task.wait(). Ive also tried looking at any other dev forum posts but only found how to check if a tween is completed(which i already knew).”

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Sadly it isn’t possible since Roblox doesn’t really give us a way to track the progress of a tween (in the documentation they call it "Progress Variables")

1 Like

Maybe you could try tracking the distance between the starting and ending position.

1 Like

How does one script this though?

1 Like

Depending on what you’re trying to tween, I would experiment with lerping. Or try @CLL10K solution.

You can get the mid point by dividing the end position by 2, then checking if the instance’s tween property to check if it’s at half. Heres an example:

local start = 0
local end1 = 1

local current = 0

local midPoint = end1/2

while current ~= midPoint do
	current += 0.1
	print(current)
end

Heres another with part tweening:

local Part = workspace.Part
local TweenService = game:GetService("TweenService")

local Info = TweenInfo.new(2)

local EndPosition = Part.Position + Vector3.new(0,10,0) -- Move 10 studs up
local MidPointY = EndPosition.Y/2 -- Get MidPoint

local Tween = TweenService:Create(Part, Info, {Position = EndPosition})

--Check if the part has reach mid point
coroutine.wrap(function()
	while task.wait() do
		print("Checking")
		if Part.Position.Y >= MidPointY then
			print("Part is at mid point")
		Tween:Pause()
		return
	end
	end
end)()

Tween:Play()

Another example with lerping:

local Part = workspace.Part

local StartCFrame = Part.CFrame
local EndGoal = StartCFrame * CFrame.new(0, 10, 0)

local Duration = 1

local CurrentTime = os.clock()

while task.wait() do
	local Alpha = math.min((os.clock() - CurrentTime) / Duration, 1)
	Part.CFrame = StartCFrame:Lerp(EndGoal, Alpha)
	
	if Alpha >= 0.5 then return end
end

But the most simplest way, tween it half way :joy::

local Part = workspace.Part
local TweenService = game:GetService("TweenService")

local Info = TweenInfo.new(2)

local EndPosition = Part.Position + Vector3.new(0,10,0)
local MidPointY = EndPosition.Y/2

local Tween = TweenService:Create(Part, Info, {Position = Vector3.new(0, MidPointY, 0)})

Tween:Play()

For @CLL10K’s solution, you could take the length of the tween and divide it by 2. Then after you start the tween:

Tween:Play()

You could just wait the amount of time you got from dividing the length by two:

task.wait(…)
print("Tween if halfway done!")

Now obviously I’m unsure if tweens are async, but if they are, then this probably would work

1 Like

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