Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a better way to Pause a Tween from a TweenService?

Since TweenService is yielding, :Pause() and :Stop() are quite inconvinient. From just using one script, is there a better way of using :Stop() on a TweenService or a better way to run multiple scripts into one? If you think using multiple scripts will make it more efficient somehow then feel free to give an explention that way. This is the best I got to pausing a TweenService so far:

local TS = game:GetService("TweenService");
local c = TS:Create(script.Parent,TweenInfo.new(1,Enum.EasingStyle.Back,Enum.EasingDirection.In,0,true,0.497),{Rotation=375});
local a;
local b;
a = game:GetService("RunService").RenderStepped:connect(function()
	a:Disconnect();
	c:Play();
end);
b = game:GetService("RunService").RenderStepped:connect(function()
	b:Disconnect();
	wait(1);
	c:Pause(); -- Pauses the TweenService right inbetween
end);

Any help with improving this is appreciated. Thanks!

1 answer

Finding this back 10 months later, I'm pretty familiar with TweenService so I'll answer my own question.

TweenService does NOT yield meaning that the Tween won't delay the script. I was confused for some reason about that. Because of this, no more issue with multiple running codes.

Second thing I noticed is that RenderStepped:connect being disconnected was the way used to run 2 things at the same time in this question. I recommend now the delay() function. It doesn't rely on an event to get disconnected and there's virtually no delay! Here's an example of using delay:

print("Since I'm using StreamingEnabled, I'm going to load these 12 parts at the same time, to be sure that the rendering system is not delaying the script so much. Parts can be differentiated by naming them with numbers at the end.")
local parts = {}
for i = 1,12 do
    delay(0,function()
        parts[i] = workspace:WaitForChild("Part",tostring(i))
    end)
end

while true do
    if #parts > 5 then -- Waits until at least 6 parts are loaded.
        break
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.