Why my multiple tweens in one object is not working?

  1. What do you want to achieve? I want make object’s position going up to right to down to back to original. Like the square way.

  2. What is the issue? Only one tween working, ignored others.

  3. What solutions have you tried so far? I searched deeply of internet to find how tweens to be in order. Which that why some code seem similar from others.

Here a code, I tried make tweens to be success and in order to make square path.


local remove = script.Parent

local info = TweenInfo.new(
	1, 
	Enum.EasingStyle.Sine, 
	Enum.EasingDirection.InOut,
	0,
	true)
-
local lift = remove.Position + Vector3.new( 0, 10, 0)
local downPosition = remove.Position + Vector3.new( 0, 0, 0)
local leftPosition = remove.Position + Vector3.new( 0, 0, 10)
local rightPosition = remove.Position + Vector3.new( 10, 0, 0)




local tween1 = TweenService:Create(remove, info, {Position = lift})
local tween2 = TweenService:Create(remove, info, {Position = leftPosition})
local tween3 = TweenService:Create(remove, info, {Position = downPosition})
local tween4 = TweenService:Create(remove, info, {Position =  rightPosition})



local function PlayTweens(PT)
	for i,k in pairs(PT) do
		k:Play()
	end
end

PlayTweens({tween1, tween2, tween3, tween4})

Any tips to fix this script?

2 Likes

PT in your function needs to be wrapped inside these {}

Alr, I put {} in it. Yet its not working. Sorry, I am beginner scripter. I trying to learn lol

local function PlayTweens{PT}
	for i,k in pairs({PT}) do
		k:Play()
	end
end

For the function, it needs to be wrapped like

Playtween({PT})

Okay, I tried it. For some reason, there error in it. Here I show you a screenshot.

Remove local and add a ) to the final end

A new tween will override a previous tween if the goal affects the same property. Instead, listen for when one tween finishes before playing the next one.

You’re playing all of them at once without waiting for each one to finish. Since playing a new tween on an already tweening instance will cancel out the already playing tween, it skipps all of them except the last one. Try this

for i, k in pairs(PT) do
k:Play()
k.Completed:Wait()
end

this way you’ll wait for the tween to complete before letting the loop continue on to the next tween
Edit: my misstake, forgot tween:Play() doesn’t return anything

This is the solution, but I’ve had bad blood with Completed:Wait() (inventory system rahh). So I’d just be wait the tween time :slight_smile:

You are moving the one instance without waiting for the previous tween to finish. Add k.Completed:Wait() after you call k:Play().

Okay, you are right about tweens play at once. I tried your code so I put in it. which not work bc of that

Screenshot 2024-09-06 220103

Do you know why?

fr, its happens rn… I having beef with that Completed:Wait() :pensive: :sob:

You need to do k.Completed:Wait(), t is nil since k:Play() : void. Basically playing the tween returns nothing. So doing t.Completed throws an error

1 Like

Woah??? that’s working. though, didn’t went square way. I will fix the position. But seriously, ur right. this is working well. Thanks!!!

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