Loop for a time?

How can I make a loop for a time?
And I don’t mean something like

local timer = 0
for i = 1, 10 do
     timer += 1

I mean something like movement. Like a fireball. And it has to be smooth.
Please help.

Why don’t you just tween the position of what you want to move?

Here is an example. This would be a script inside of a fireball:

local tweenService = game:GetService("TweenService") --// The TweenService

local fireball = script.Parent --// The fireball

local endPos = workspace.FireballHit.Position --// A part in workspace that will be where the fireball moves to

local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) --// Creates a TweenInfo to be used in the tween. Change the EasingStyle to Enum.EasingStyle.Quad for a cooler effect
tweenService:Create(fireball, info, {Position = endPos}):Play() --// Creates a tween for the fireball with the tween info, which will move it to the endPos. After creating it, the tween plays with the :Play() method

I don’t like using tween as it isn’t as “auto” as in it has a set time(that affects speed), so if it were to move 10 studs in 10 seconds it’d be slow, but 100 studs would be fast. Also, I want to use something like cframe and mouse lookvector more than tween.

You can use delta time to make it smooth and compensate for any frame drops:

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