Tween not pausing on CFrame linear movement

I am facing yet again this problem where I am giving a pause() and yet again its not pausing on command. I am baffled with this problem. I have done a post about this but on a rotating tween service here, which was solved.

Can someone please explain why this is happening? and possible fixes?

TweenService = game:GetService("TweenService")
local os1 = script.Parent.Parent.Parent
local part = script.Parent

local tweenInfo = TweenInfo.new(
	3, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	2 -- DelayTime
)

local tween = TweenService:Create(part, tweenInfo, {CFrame = CFrame.new(533.024, 85.495, -107.397)})


local function pauseTween()
	local PlaybackState = tween.PlaybackState
	if PlaybackState ~= Enum.PlaybackState.Paused then
		print("Pausing")
		tween:Pause()
	end
end

local function playTween()
	local PlaybackState = tween.PlaybackState
	if PlaybackState ~= Enum.PlaybackState.Playing then
		print("Playing")
		tween:Play()
	end	
end


tween:GetPropertyChangedSignal("PlaybackState"):Connect(function()
	local PlaybackState = tween.PlaybackState
	--if PlaybackState == Enum.PlaybackState.Playing or PlaybackState == Enum.PlaybackState.Paused then
	print(tostring(PlaybackState))
	--end
end)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
print("Completed")
1 Like

its because its searching if its pause before pausing it you should revert it like this:

local function pauseTween()
	local PlaybackState = tween.PlaybackState
	if PlaybackState ~= Enum.PlaybackState.Playing then --change it to playing
		print("Pausing")
		tween:Pause()
	end
end

local function playTween()
	local PlaybackState = tween.PlaybackState
	if PlaybackState ~= Enum.PlaybackState.Paused then --change it to pause
		print("Playing")
		tween:Play()
	end	
end

This will not fix the problem. That is there to not pause/play the state again if it is all ready paused/playing

my bad didnt notice the ~= (not enough chars)

Hey, this is because the tween is entering the Enum.PlaybackState.Delayed state as you’re pausing it. (the 2 second delay time you’ve set in tweenInfo)

This should work with your code. I just added an extra variable that double checks if a tween if supposed to be paused or running.

TweenService = game:GetService("TweenService")
local os1 = script.Parent.Parent.Parent
local part = script.Parent

local tweenInfo = TweenInfo.new(
	3, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	2 -- DelayTime
)

local tween = TweenService:Create(part, tweenInfo, {CFrame = CFrame.new(533.024, 85.495, -107.397)})

local running = false
local function pauseTween()
	local PlaybackState = tween.PlaybackState
	print("Pausing")
	running = false
	tween:Pause()

end

local function playTween()
	local PlaybackState = tween.PlaybackState
	print("Playing")
	running = true
	tween:Play()
end


tween:GetPropertyChangedSignal("PlaybackState"):Connect(function()
	local PlaybackState = tween.PlaybackState
	if PlaybackState == Enum.PlaybackState.Playing and running == false then
		tween:Pause()
	elseif PlaybackState == Enum.PlaybackState.Paused and running == true then
		tween:Play()
	end
	--if PlaybackState == Enum.PlaybackState.Playing or PlaybackState == Enum.PlaybackState.Paused then
	print(tostring(PlaybackState))
	--end
end)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
wait(10)

playTween()
wait(10)

pauseTween()
print("Completed")
2 Likes

Thank you again for helping me out

1 Like