Part not tweening

I have a tween system to open and close doors but only the opening is working.

local ts = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local right1 = script.Parent.Door.Union1.Position
local right2 = script.Parent.Door.Union.Position
local left1 = script.Parent.Door2.Union1.Position
local left2 = script.Parent.Door2.Union.Position
local db = false
local function opendoors()
	local openright1 = ts:Create(script.Parent.Door.Union1,tweeninfo, {Position = right1 + Vector3.new(0,0,5)})
	local openright2 = ts:Create(script.Parent.Door.Union, tweeninfo, {Position = right2 + Vector3.new(0,0,5)})
	local openleft1 = ts:Create(script.Parent.Door2.Union1,tweeninfo, {Position = left1 + Vector3.new(0,0,-5)})
	local openleft2 = ts:Create(script.Parent.Door2.Union, tweeninfo, {Position = left2 + Vector3.new(0,0,-5)})
	openright1:Play()
	openright2:Play()
	openleft1:Play()
	openleft2:Play()
end



local function closedoors()
	
	
	local function opendoors()
		local closeright1 = ts:Create(script.Parent.Door.Union1,tweeninfo, {Position = Vector3.new(140.517, 19.114, -102.107)})
		local closeright2 = ts:Create(script.Parent.Door.Union, tweeninfo, {Position = Vector3.new(140.516, 19.314, -102.105)})
		local closeleft1 = ts:Create(script.Parent.Door2.Union1,tweeninfo, {Position = Vector3.new(140.507, 19.314, -107.306)})
		local closeleft2 = ts:Create(script.Parent.Door2.Union, tweeninfo, {Position = Vector3.new(140.508, 19.114, -107.308)})
		closeright1:Play()
		closeright2:Play()
		closeleft1:Play()
		closeleft2:Play()
	end
	
	
end


script.Parent.Entrance.Touched:Connect(function(hit)
	
	if db == false then
		db = true
		opendoors()
		wait(1)
		closedoors()
		wait(2)
		db = false
	end

	
end)

that is my code. If anyone knows the issue please help thanks :smiley:

That’s because your close doors function just creates a new open doors function inside it that never gets called. So it essentially does nothing.


local function closedoors()
	
	
	local function opendoors()
		local closeright1 = ts:Create(script.Parent.Door.Union1,tweeninfo, {Position = Vector3.new(140.517, 19.114, -102.107)})
		local closeright2 = ts:Create(script.Parent.Door.Union, tweeninfo, {Position = Vector3.new(140.516, 19.314, -102.105)})
		local closeleft1 = ts:Create(script.Parent.Door2.Union1,tweeninfo, {Position = Vector3.new(140.507, 19.314, -107.306)})
		local closeleft2 = ts:Create(script.Parent.Door2.Union, tweeninfo, {Position = Vector3.new(140.508, 19.114, -107.308)})
		closeright1:Play()
		closeright2:Play()
		closeleft1:Play()
		closeleft2:Play()
	end
	
	
end

To fix it just remove the lines that make the code part of an inner function

local function closedoors()
		local closeright1 = ts:Create(script.Parent.Door.Union1,tweeninfo, {Position = Vector3.new(140.517, 19.114, -102.107)})
		local closeright2 = ts:Create(script.Parent.Door.Union, tweeninfo, {Position = Vector3.new(140.516, 19.314, -102.105)})
		local closeleft1 = ts:Create(script.Parent.Door2.Union1,tweeninfo, {Position = Vector3.new(140.507, 19.314, -107.306)})
		local closeleft2 = ts:Create(script.Parent.Door2.Union, tweeninfo, {Position = Vector3.new(140.508, 19.114, -107.308)})
		closeright1:Play()
		closeright2:Play()
		closeleft1:Play()
		closeleft2:Play()
	
	
end

I copy and pasted the first function I didn’t see that lol

it works thanks! have a great day

1 Like