How would I stop this tween to play another?

So my script is…

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Type.Text == "69372" then ---Tryna make it so if this is entered
		script.Parent.Parent.Result.Text = "Task Completed!" --- and it says this then
		wait(1)
		script.Parent.Parent:TweenPosition(UDim2.new(1,0,0,0)) -- It moves off my screen
		wait(2)
		script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,351,0,24), "Out", "Linear", 5, false) --- then make these two work so the task bar goes up.
		wait(00.1)
		script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,395,0,24), "Out", "Linear", 5, false)
	else
		script.Parent.Parent.Result.Text = "Task Failed!"
		wait(1)
		script.Parent.Parent:TweenPosition(UDim2.new(1,0,0,0))
	end
end)

I tested my game and looked through the scripts many times.

And I think that

script.Parent.Parent:TweenPosition(UDim2.new(1,0,0,0)) -- It moves off my screen

is still running so it wont play this tween here

script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,351,0,24), "Out", "Linear", 5, false) --- then make these two work so the task bar goes up.
		wait(00.1)
		script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,395,0,24), "Out", "Linear", 5, false)

any fixes?
Note: there aren’t any errors, the only problem is that two Tweens that look the same above aren’t working. but there aren’t any errors.

I am not really sure to understand why this is don’t work :confused: . Personally i used something like this and is work pretty well

Tween = function(Obj, Time, Settings)	
	game:GetService("TweenService"):Create(Obj, TweenInfo.new(Time), Settings):Play()
end

after you can set the tween with

-- 1 arg = Obj, 2 arg = Time for move to the Position (arg 3) 
    Tween(script.Parent.Parent, 2, {Position = UDim2.new(1,0,0,0)}) 
wait(2)
print("Do something after")

If you want to stop a tween, the easiest and most understandable method is to use TweenService instead of UI functions.
There are :Play() and :Stop() functions in TweenObjects. If you wish to stop a tween, just use :Stop().

2 Likes

I will see if “:Stop()” works. I will be back.

That didn’t work, I think I may have did it wrong. Could You edit my script with em?

TweenSize, TweenPosition and TweenSizeAndPosition don’t return a userdata where you can call methods on them - it’s only with TweenService:Create where you can :Play and :Stop a tween.
TweenService:Create (roblox.com)

So how could I fix my script to make it work? I have been spending hours

If two tweens are trying to transform the same property, the second one will take over when you play it. You don’t have to stop the first one to play the second one.

As per the documentation:

1 Like

what does it mean same property.? same script? like im so confused

Same property such as position. Say you have two tweens:
TweenA tries to make the position (1,0,0,0)
TweenB to make the position (0,0,0,0)

If you play TweenA, and play tweenB while tweenA is playing, tweenB will take over and cancel tweenA, since they are both attempting to tween the same “Position” property.

wait so

script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,351,0,24), "Out", "Linear", 5, false) --- then make these two work so the task bar goes up.
		wait(00.1)
		script.Parent.Parent.Parent.TaskBarBackground.TaskBar:TweenSize(UDim2.new(0,395,0,24), "Out", "Linear", 5, false)

is the problem? or what

I am trying to say that if you were worried about two tweens playing on the same object being the problem, that isn’t it.

Try changing your wait to 5 seconds and see if it works.

which wait? and sorry if i’m being dumb its like 1 am

It’s ok :slight_smile: sorry for not specifying. This one in the three lines you sent:
image

1 Like

Oh my god! thank you alot. that worked. :heart: :heart:

1 Like