Bunker door will not close after opening

Code:

local Puzzle = script.Parent

local LeftSignal = Puzzle:WaitForChild("LeftSignal")

local RightSignal = Puzzle:WaitForChild("RightSignal")

local CS = game:GetService("CollectionService")

local AvailableColors = {
	Color3.fromRGB(255, 89, 89);
	Color3.fromRGB(213, 115, 61);
	Color3.fromRGB(255, 255, 0);
	Color3.fromRGB(70, 209, 102);
}

local SignalColors = {
	Solved = Color3.fromRGB(70, 209, 102);
	NotSolved = Color3.fromRGB(255, 89, 89);
}

local ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]

for _, ChangeableColor in pairs(CS:GetTagged("ChangeableColor")) do

	ChangeableColor.ClickDetector.MouseClick:Connect(function()
		
		if ChangeableColor.Color ~= ChosenTargetColor then
			
			ChangeableColor.Color = AvailableColors[math.random(1,#AvailableColors)]
			
		end
		
	end)

end

local BunkerDoor = Puzzle:WaitForChild("BunkerDoor")

local ClosingTimeIndicator = BunkerDoor:WaitForChild("ClosingTimeIndicator")

local LeftHinge = BunkerDoor:WaitForChild("Hinges"):WaitForChild("LeftHinge")

local RightHinge = BunkerDoor:WaitForChild("Hinges"):WaitForChild("RightHinge")

local BunkerDoorOpenTime = 30

local AnimInfo = TweenInfo.new(4.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)

local TS = game:GetService("TweenService")

while true do
	
	ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]
	
	LeftSignal.Signal.Color = SignalColors.NotSolved
	
	RightSignal.Signal.Color = SignalColors.NotSolved
	
	for _, TargetColor in pairs(CS:GetTagged("TargetColor")) do
		
		TargetColor.Color = ChosenTargetColor
		
	end
	
	for _, ChangeableColor in pairs(CS:GetTagged("ChangeableColor")) do

		local ColorToSet

		repeat

			ColorToSet = AvailableColors[math.random(1,#AvailableColors)]

			task.wait()

		until ColorToSet ~= ChosenTargetColor

		ChangeableColor.Color = ColorToSet

	end
	
	local CorrectLeftColors
	
	local CorrectRightColors
	
	repeat
		
		CorrectLeftColors = 0
		
		CorrectRightColors = 0
		
		for _, ChangeableColor in pairs(CS:GetTagged("ChangeableColor")) do

			if ChangeableColor.Color == ChosenTargetColor then
				
				if ChangeableColor.Parent.Name == "LeftStar" then

					CorrectLeftColors += 1

				elseif ChangeableColor.Parent.Name == "RightStar" then

					CorrectRightColors += 1

				end
				
			end
			
		end
		
		if CorrectLeftColors == 4 then
			
			LeftSignal.Signal.Color = SignalColors.Solved
			
		end
		
		if CorrectRightColors == 4 then

			RightSignal.Signal.Color = SignalColors.Solved

		end
		
		task.wait()
		
	until CorrectLeftColors == 4 and CorrectRightColors == 4
	
	local LeftHingeChange1 = {CFrame = LeftHinge.CFrame * CFrame.Angles(math.rad(-120),0,0)}
	
	local RightHingeChange1 = {CFrame = RightHinge.CFrame * CFrame.Angles(math.rad(120),0,0)}
	
	TS:Create(LeftHinge,AnimInfo,LeftHingeChange1):Play()
	
	TS:Create(RightHinge,AnimInfo,RightHingeChange1):Play()
	
	task.delay(4.5,function()
		
		for secs = BunkerDoorOpenTime,0,-1 do

			ClosingTimeIndicator:WaitForChild("UI"):WaitForChild("TimeDisplay").Text = "Closing in " .. secs .. "s"

			task.wait(1)

		end
		
		ClosingTimeIndicator:WaitForChild("UI"):WaitForChild("TimeDisplay").Text = ""
		
	end)
	
	task.wait(BunkerDoorOpenTime)
	
	local LeftHingeChange2 = {CFrame = LeftHinge.CFrame * CFrame.Angles(0,0,0)}

	local RightHingeChange2 = {CFrame = RightHinge.CFrame * CFrame.Angles(0,0,0)}

	TS:Create(LeftHinge,AnimInfo,LeftHingeChange2):Play()

	TS:Create(RightHinge,AnimInfo,RightHingeChange2):Play()
	
	task.wait(4.5)
	
end

Issue:

local LeftHingeChange2 = {CFrame = LeftHinge.CFrame * CFrame.Angles(0,0,0)}

	local RightHingeChange2 = {CFrame = RightHinge.CFrame * CFrame.Angles(0,0,0)}

	TS:Create(LeftHinge,AnimInfo,LeftHingeChange2):Play()

	TS:Create(RightHinge,AnimInfo,RightHingeChange2):Play()

After the 30 second with the bunker will not close.

1 Like

Try reversing the numbers when you want to close the door.

local LeftHingeChange2 = {CFrame = LeftHinge.CFrame * CFrame.Angles(math.rad(120),0,0)}

local RightHingeChange2 = {CFrame = RightHinge.CFrame * CFrame.Angles(math.rad(-120),0,0)}

Are the colors changing?
You have a lot of checks going on. Try printing the variables before if and until statements like this:

print("left color = ", CorrectLeftColors, "    right color = ", CorrectRightColors)
until CorrectLeftColors == 4 and CorrectRightColors == 4

It’ll tell you if those variables get to 4.
Is it possible you just need both to be over 4? The way your code is now if left changes from 3 to 4 but right is already 5 then the until won’t pass the check. In that case you should have >= instead of == for both.

Yes it does change. The colors arent the problem. Its the bunker not closing for some reason.

Why are you doing a task.delay() function?

whats wrong with it?
///////////////////////////

idk if you need one, because you already have a wait time from the time to close. (idk if this will help, just try to see)

after 4.5 seconds it will open a new thread so the rest of the script can continue but it will still do what code is in the delay function

Ok, that tells us that that section of the code is working properly.

My suggestion of printing variables is good for troubleshooting to see why code isn’t doing what is expected.

Anyway, why are you setting the Tween parameters (like LeftHingeChange1 and 2 as well as RightHingeChange1 and 2 and the creating the tween (TS:Create(LeftHinge, …) every single time the while true do loop runs? Why not set it up before the while true do loop at the beginning of the script?

A much simpler way of doing this is to fire a function only when the LeftStar and RightStar numbers actually change instead of using the loop that runs all the time would be more efficient. Then just play the tween(s) when both the values are 4.