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

Most optimized way to loop a tween?

So my question is this: What's the best/ most efficient/ fastest way to run a tween in a 'RenderStepped' loop?

I've got a tween that is constantly running in such a loop and because of this, the Script performance output for that script reads around 2-4. This seems a bit high and it's definitely higher then I'd like, so how do I get this number down?

Guess I'll include some sample code:

local Render_Stepped =game:GetService("RunService").RenderStepped
local Offset =Vector3.new(0,0,-20)
local Tween_Service =game:GetService("TweenService")
local tweenInfo =TweenInfo.new(
	0.1,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local Dynamic_MousePose =script.D_MPoint --A Vector3 Value

Render_Stepped:connect(function()
	local goal ={Value =Camera.CoordinateFrame*Offset}
	local tween =Tween_Service:Create(Dynamic_MousePose,tweenInfo,goal):Play()
	V_Model:SetPrimaryPartCFrame(CFrame.new(PL_Head.CFrame.Position,Dynamic_MousePose.Value)*V_Offset*V_Rotation)
end)

Some things to keep in mind: Almost ALL values are constantly changing, which is why I'm constantly tweening. (So the position floats to the new end value)

There may be a better way altogether to achieve this same function, if so, please share it!

Thanks.

1 answer

To make a tween loop indefinitely use -1 as the repeat time, but to make it loop x times use a for i = 1, x, 1 do loop

2 comments

0

Unfortunately I don't think that will work, as 'goal' and 'tween' need to constantly be updated to new values.

0

True

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