Door tweening not working

READ UNTIL END

Here is my code:

local touchPart = script.Parent.touchPart
local a = script.Parent.DoorA
local b = script.Parent.DoorB

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1.584,Enum.EasingStyle.Circular)

local aOpen = tweenService:Create(a,tweenInfo,{CFrame = a.CFrame + a.CFrame.ZVector * 4.4})
local aClosed = tweenService:Create(a,tweenInfo,{CFrame = a.CFrame})
local bOpen = tweenService:Create(b,tweenInfo,{CFrame = b.CFrame + b.CFrame.ZVector * -4.4})
local bClosed = tweenService:Create(b,tweenInfo,{CFrame = b.CFrame})

local inaction = false

local function Open()
	if inaction == false then
		inaction = true
		script.Parent.lightA.BrickColor = BrickColor.new("Lime green")
		aOpen:Play()
		bOpen:Play()
		script.Parent.Sound:Play()
		aOpen.Completed:Wait()
		bOpen.Completed:Wait()
		inaction = false
	end
end

local function Close()
	if inaction == false then
		inaction = true
		script.Parent.lightA.BrickColor = BrickColor.new("Really red")
		aClosed:Play()
		bClosed:Play()
		script.Parent.Sound:Play()
		aClosed.Completed:Wait()
		bClosed.Completed:Wait()
		inaction = false
	end
end

touchPart.Touched:Connect(function()
	print("open")
	Open()
end)

touchPart.TouchEnded:Connect(function()
	print("close")
	Close()
end)

and here are the items in the explorer:

image

And when I touch the part, the door does open but when I stop touching the part and reach the other side of the door the door doesn’t close, even though it DOES print out “close”.

I am completely and utterly baffled so any help would be greatly appreciated.
Thanks.

1 Like

Would anyone mind acutally helping me and actually giving answers to try and solve the problem?

These are probably dumb, sorry in advance:

  • I presume then “touchPart” is a sensor sort of thing for your door? The doors can be touching that part and cause an infinite open() loop.
  • Maybe you leave the sensor too quickly before the inaction value goes false? If that’s the case, its pretty normal for your close() function to not run.


    I think these can be causing your problem. Apologies again.

Yup, I was testing it excessively a few days ago and realised the functions were causing in infinite open() and close() loop so I had to do some debouncing and use some extra parts to make it work. And by the way, these suggestions were NOT dumb, what do you mean??!?!?!?!??!!

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