Tween having issues?

Whenever the touched function is activated. the tween gets to line 18, doesnt wait and instantly does the second tween. the first tween seems to cancel out the second tween. making it so the second tween doesnt even happen. What is the issue?



local detectionZone = script.Parent
local debounce = false

local function onTouched(other)

	local character = other.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	local tool = character:FindFirstChild("Card")


	if humanoid and tool then
		
		if debounce == true then return end
		debounce = true
		print("works?")
		game:GetService("TweenService"):Create(game.Workspace.Door125Main, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CFrame = CFrame.new(-136.094, 1.524, -187.613) * game.Workspace.Door125Main.CFrame.Rotation}):Play()

		wait(1)
		game:GetService("TweenService"):Create(game.Workspace.Door125Main, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CFrame = CFrame.new(-132.394, 1.524, -187.613) * game.Workspace.Door125Main.CFrame.Rotation}):Play()
        print("Tween REstart")


		task.wait(3)
		debounce = false
	end

end

detectionZone.Touched:Connect(onTouched)

1 Like

I’m not quite sure what the issue is there, but I would recommend using the Completed event.

This is entirely optional, but I would also recommend using a function that’s a little easier to use:

local tweenService = game:GetService('TweenService')
function tween(object,array,speed,style,direction)
	style = style or Enum.EasingStyle.Linear
	direction = direction or Enum.EasingDirection.InOut
	local tweenInfo = TweenInfo.new(speed,style,direction)
	return tweenService:Create(object,tweenInfo,array)
end

With that, it would look like this:

local tweenService = game:GetService('TweenService')
function tween(object,array,speed,style,direction)
	style = style or Enum.EasingStyle.Linear
	direction = direction or Enum.EasingDirection.InOut
	local tweenInfo = TweenInfo.new(speed,style,direction)
	return tweenService:Create(object,tweenInfo,array)
end

local detectionZone = script.Parent
local debounce = false

local function onTouched(other)

	local character = other.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	local tool = character:FindFirstChild("Card")


	if humanoid and tool then

		if debounce == true then return end
		debounce = true
		print("works?")
		local anim = tween(workspace.Door125Main,{CFrame=CFrame.new(-136.094,1.524,-187.613)*game.Workspace.Door125Main.CFrame.Rotation},1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
		anim:Play()
		anim.Completed:Wait()
		anim = tween(workspace.Door125Main,{CFrame=CFrame.new(-132.394,1.524,-187.613)*game.Workspace.Door125Main.CFrame.Rotation},1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)
		anim:Play()
		anim.Completed:Wait()
		anim = nil
		print("Tween REstart")


		task.wait(3)
		debounce = false
	end

end

detectionZone.Touched:Connect(onTouched)

Note that the last two inputs of easing style and direction are both optional, their defaults are Linear
and InOut.

Works for some reason now… thank you!

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