You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to Fix the problem that I am having with Tweening a part in my game that is supposed to move back and forth
What is the issue? Include screenshots / videos if possible!
I have the chords that I want it to go to imputed but it completly messes up the order and goes in the direction that It is not supposed to and I am very confused on why it is doing this
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried testing the script and tried rearranging it but it still acts the same way
local thechoclate = script.Parent:FindFirstChild("Part")
local Tween = TweenInfo.new(
5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
local Tweenservice = game:GetService("TweenService")
local work = Tweenservice:Create(thechoclate, Tween, {Position = Vector3.new(thechoclate.Position.X, thechoclate.Position.Y, thechoclate.Position.Z - 422.422)})
local work1 = Tweenservice:Create(thechoclate, Tween, {Position = Vector3.new(thechoclate.Position.X, thechoclate.Position.Y, thechoclate.Position.Z + 422.422)})
while wait(10) do
work:Play()
wait(5)
work1:Play()
end
The Tween is only applying to the Z direction of the part and I have no idea why it’s out of order. I have the first tween playing to move it forward and the other tween to move it back to its original spot. Thanks for any help.
I tested your code in my own baseplate with a normal BasePart, and it works okay, although i noticed some things in your code that stuck out to me and that was the fact that you are using wait(). For people on slower devices this will cause issues, so I would recommend using the Completed RBXScriptSignal for tweens. you can do this by replacing that whole loop with:
while true do
work:Play()
work.Completed:Wait()
work1:Play()
work1.Completed:Wait()
end
For the future, I heard that using task.wait() is much smarter than using wait() and here is that topic explaining why! task.wait(n) vs wait(n).
But the reason you will want to use Completed:Wait() is because it will wait until the tween is finished before firing the next segment of code, which is much better than relying on wait() or even task.wait().
If you still want to have that extra 5 seconds before your code fires again, you can add a task.wait(5) at the end of the loop right below work1.Completed:Wait(). and while true do keeps the loop running infinitely. You can even add a task.wait(seconds) in between after any of the Completed:Wait() lines to add a slight pause before the next tween plays!
If you are still having issues with the tween looking wonky, I would use Enum.EasingDirection.Out instead but thats all just a matter of playing around with things!! Hope this helped you!
If you want to have the part move from the original position, to your said coordinates, you can add a variable that gets the position of the part prior to it moving.
Below is the updated script:
local thechoclate = script.Parent:FindFirstChild("Part")
local choclateposition = thechoclate.Position -- Gets the original part position
local Tween = TweenInfo.new(
5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false,
0
)
local Tweenservice = game:GetService("TweenService")
local work = Tweenservice:Create(thechoclate, Tween, {Position = Vector3.new(thechoclate.Position.X, thechoclate.Position.Y, thechoclate.Position.Z - 422.422)})
local work1 = Tweenservice:Create(thechoclate, Tween, {Position = Vector3.new(choclateposition)})
while task.wait(10) do
work:Play()
work.Completed:Wait()
task.wait(10) -- Waits 10 seconds before playing work1
work1:Play()
work1.Completed:Wait()
end
The script should work as expected now. However, I noticed a few things that could be touched on, so I changed the script a little. They’ve already been mentioned in the reply above mine, but I’m still going to talk about them regardless.
Use task.wait() instead. The reason is that wait() is deprecated. When possible, refrain from using deprecated functions.
Unless you desire having the tween play exactly five seconds in-between each tween, it’s generally better to use TweenNameHere.Completed:Wait. (that’s if you want the second tween to run right after the first one)
There are other things that came to mind, but I think that would be out of scope for this post. So, I hope my script fixed the problem, good day.
thanks a lot, I had to made some tweaks to the script you sent but it worked and thanks for the rundown on task.wait() and Completed:Wait, I guess I need to go back to all of my scripts and change the Wait() now lol