Hi. I’m having some huge trouble deciding what to use for part movement. …TweenService…? Or RunService…? I don’t know what to choose…
What do you want to achieve? An efficent way of moving parts.
What is the issue? …Not knowing which service to use.
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:
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. ;-;
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 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.
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: