Tween Stops When Player Clicks!

Problem: When the player touches a part, I play a simple Tween but, as soon as the player clicks or Clicks a Key, the tween stops working.

local TweenSevice = game:GetService(“TweenService”)
local cuttime = 2
local Tweenpart1 = game.Workspace.LobbyItems.MenuCams:WaitForChild(“Cam1”)
local Tweenpart2 = game.Workspace.LobbyItems.MenuCams:WaitForChild(“Cam2”)
local Tweeninfo = TweenInfo.new(

cuttime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0

)

part.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

	Cam.CameraType = Enum.CameraType.Scriptable
	Cam.CFrame = Tweenpart1.CFrame
	
	local tween = TweenSevice:Create(Cam,Tweeninfo,{CFrame = Tweenpart2.CFrame}) --- getting tween info 
	tween:Play()--Playig it
	
	wait(cuttime)
	
	Cam.CFrame = Tweenpart2.CFrame
	
	
	
	
end

end)

Hello! You can use this code to stop a tween animation:

TweenAnimation:Cancel()

So you can do a function with a click detector like this code:

local Type = true  -- True = will move         /         False = will stop
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(
	5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut,
	0,
	false
)
local part = script.Parent
local Animation = TweenService:Create(part,Info, {Position = Vector3.new(124.1, 0.5, -8.45)})

script.Parent.ClickDetector.MouseClick:Connect(function()
	if Type == true then
		Animation:Play()
		Type = false
		print("Tween Started")
	else
		Animation:Cancel()
		Type = true
		print("Tween Stopped")
	end
end)

postscript: I speak Spanish, sorry if I wrote something wrong.

1 Like

thank you very much I think a click detector would work better :wink: