TweenService or RunService?

Hi. I’m having some huge trouble deciding what to use for part movement. …TweenService…? Or RunService…? I don’t know what to choose…

  1. What do you want to achieve? An efficent way of moving parts.

  2. What is the issue? …Not knowing which service to use.

  3. What solutions have you tried so far? …I don’t know how to use RunService for moving parts… so I’ve only used TweenService for now.

Also, for some reason… my TweenService movement… is… not working? I mean. It works… but it just doesn’t move the way I want it.
Here’s an example:
Expectation:

START AND FINISH IS SUPPOSED TO LOOK LIKE THIS

Reality:


Apologies for different angles. The spikes got deleted somehow, so I had to bring them back. (THE FINISH IS NOT SUPPOSED TO END LIKE THIS.)

If you can tell me what is better… TweenService, or RunService… I will be super grateful. However, if you can also help me fix this script issue, I will also be super grateful.

Here is the code.

local TweenService = game:GetService("TweenService")

Spike = script.Parent

Tweens = TweenInfo.new(
	
	16, -- Speed
	Enum.EasingStyle.Sine, -- The part moving animation. (EASING STYLE)
	Enum.EasingDirection.InOut, -- What direction it moves in. (EASING DIRECTION)
	0, -- How many times it loops. (REPEAT COUNT)
	false, -- (REVERSES)
	0 -- Delays before repeating itself... but if you have repeat count set to 0.. then..
)

local Animator = TweenService:Create(Spike, Tweens, {Position = Spike.Position-Vector3.new(0, 0, 1000)})
Animator:Play()
task.wait(15)

script.Parent.Parent:Destroy()

I don’t have any RunService code, so if you could tell me what RunService is as well, I will be very grateful. Again… this is what I want:
1: Knowing which movement method is most efficient.
2: Letting me know what’s wrong with the code above, which is causing my parts to move IN, instead of moving straight. (Yes, I checked to make sure it was the right Axis. And it is.) OR, giving me an example of what to use for RunService.
3: Not arguing, that confuses me. ;-;

1 Like

You put 0 in the place of how long the tween should last in your TweenInfo table (the fourth argument is time, if I am correct, not repeat count). This means it lasts for 0 seconds…

The properties are in this order: (Time,EasingStyle,EasingDirection,RepeatCount,Reverses,DelayTime)

Or, copied from the roblox wiki,

local tweenInfo = TweenInfo.new(
	2, -- 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)
	0 -- DelayTime
)

So the OP has the correct TweenInfo.

It moves. The time is at the beginning I think. I called it speed.

But, the thing is… the parts do not move straight. Like, they move in towards the Z axis. However, they go inward. I do not want them to go inward.

If you need more info, compare these two pictures.


WHAT IT SHOULD LOOK LIKE, EVEN WHEN MOVING.

WHAT IT LOOKS LIKE WHEN IT DOES MOVE

I’m gonna hope I get some help… these topics die really fast, which is why my problem never gets solved.

The former is alright, the latter caps on frame rate and cause things to “lag” when you are throttling on frame rates, which doesn’t happen always.

So there is a change in offset between the parts?
Could you provide further details on what you want to do? The code you provided only moves a single part so I assume you apply this code for every part?

One problem I immediately see is that scripts won’t start running exactly at the same time on game load Try moving every part from the same script.

I found a custom tween implementation using RunService to be faster for moving many parts than using TweenService, but I highly doubt you will run into any performance issues in this case.

Generally a good rule of thumb is to only think about performance when you actually have to.

Sorry. I’m trying to explain it best I can. The spikes only need to move on the Z Axis. However, they are moving on both the Z and X Axis. But the other Axis are set to 0, which is why I am so confused on why the spikes are still moving on the X Axis along with the Z Axis. Is that just a problem with TweenService? Do I need to switch to RunService? If so, please, let me know. I’m so confused. I’ve made over 6 posts about this, and I still have no answers.

Another movement method I might suggest would be to simply hook the spikes up to Prismatic Constraints. Then all you need to do in the code is simply change the “TargetPosition” property of the constraints.

Alright. I’ll try your method and see.

Any other ideas, please tell me them.

It you still wonder why they go like that on the z axis still, it probably just the Easing Direction or Easing Style

I tried to recreate the issue using the script you provided, but I did not observe the part moving along the X axis. However, if I am understanding the problem correctly, my suggestion would be to change the part’s CFrame instead of its position, as such:

Animator = TweenService:Create(Spike, Tweens, {CFrame = CFrame.new(Spike.Position-Vector3.new(0, 0, 1000)) * Spike.CFrame.Rotation})

I am not certain this will fix the specific issue you are having, but it has fixed similar problems for me in the past.

Thank you. But it has been fixed. It turns out I was missing the table as shown on the Dev Forum, which is

local Goal = {}
Goal.Position = Vector3.new(0.5, 7, 9) -- These are just random numbers.

Hi Hecker,

Do you still face a problem with using TweenService? If so please specify what your goal is.

Well, my TweenService issue was fixed. I’m not sure how to use RunService though. At first it was moving all wonky with Tweening, but it’s fine now.