How to disable a specific piece of a script?

This is a script that tweens the part to the right side when the tool is activated, and tweens it to the left side when the tool is deactivated.

local MovePart = workspace.MovePart
local TS = game:GetService("TweenService")
local Tool = script.Parent
local TI1 = TweenInfo.new(10, Enum.EasingStyle.Linear)

local TI2 = TweenInfo.new(1, Enum.EasingStyle.Linear)

local goal1 = {}
goal1.Position = Vector3.new(67, 7, 3)
local Tween1 = TS:Create(MovePart,TI1,goal1)

local goal2 = {}
goal2.Position = Vector3.new(17,7,3)
local Tween2 = TS:Create(MovePart,TI2,goal2)

Tool.Activated:Connect(function()
	Tween1:Play()
end)

Tool.Deactivated:Connect(function()
	Tween1:Pause()
	Tween2:Play()
end)

Tween1.Completed:Connect(function()
	if MovePart.Position == Vector3.new(67,7,3) then
		print("The tween has been completed!")
	end
end)

How can I disable that Deactivation event when the Completed event is fired?

Is it possible?

2 Likes

You can disconnect the connection.

local connection = Tool.Deactivated:Connect(function()
    connection:Disconnect()
end)
2 Likes

Thank you so much!

It works:))

2 Likes

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