Why is my door only opening in one direction?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear! Trying to make it open the opposite direction from when the player is entering or leaving from the building.

  2. What is the issue? Look on the video to find out what I am talking about - - YouTube

  3. What solutions have you tried so far? I been trying to change the code and still haven’t got good luck.

I just want to find out why it doesn’t open in a certain direction depending on if they’re leaving or entering the building.

local ServerStorage = game.ServerStorage

local IsOpen = game.ServerStorage["Robberys"]["Jewelry Store"]["Status"]["IsOpen"]

local TimeAfterClose = 3
local LeftHinge = script.Parent.LeftDoor.PrimaryPart
local RightHinge = script.Parent.RightDoor.PrimaryPart
local Enter = script.Parent.Enter
local Leave = script.Parent.Leave
local opened = false

local connection
local connection2

-- Fires when the player trys to enter the building
function OpenDoor1(hit,player)
	if hit.Parent:FindFirstChild("Humanoid") then
		player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player ~= nil then
			if connection then
				connection:Disconnect()

				if not opened and IsOpen.Value then
					opened = true
					for i = 1, 18 do
						script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
						script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
						game:GetService("RunService").Stepped:Wait()
					end
					wait(TimeAfterClose)
					for i = 1, 18 do
						script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
						script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
						game:GetService("RunService").Stepped:Wait()
					end
					opened = false

					wait(0.5)

					connection = Enter.Touched:Connect(OpenDoor1)
				end
			end
		end
	end
end

-- Fires when the player trys to leave the building
function OpenDoor2(hit,player)
	if hit.Parent:FindFirstChild("Humanoid") then
		player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player ~= nil then
			if connection2 then
				connection2:Disconnect()

				if opened == false then
					opened = true
					for i = 1, 18 do
						script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
						script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
						game:GetService("RunService").Stepped:Wait()
					end
					wait(TimeAfterClose)
					for i = 1, 18 do
						script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
						script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
						game:GetService("RunService").Stepped:Wait()
					end

					opened = false

					wait(0.5)

					connection2 = Leave.Touched:Connect(OpenDoor2)
				end
			end
		end
	end
end

connection = Enter.Touched:Connect(OpenDoor1)
connection2 = Leave.Touched:Connect(OpenDoor2)

The issue here is you made it at the end of the script able to be touched from both sides so anyone can activate both scripts at the same time,

First Solution

the solution is to make a debounce value, here is ur script but edited

local ServerStorage = game.ServerStorage

local IsOpen = game.ServerStorage["Robberys"]["Jewelry Store"]["Status"]["IsOpen"]

local TimeAfterClose = 3
local LeftHinge = script.Parent.LeftDoor.PrimaryPart
local RightHinge = script.Parent.RightDoor.PrimaryPart
local Enter = script.Parent.Enter
local Leave = script.Parent.Leave
local opened = false
local Debounce  = false
local connection
local connection2

-- Fires when the player trys to enter the building
function OpenDoor1(hit,player)
	if hit.Parent:FindFirstChild("Humanoid") then
		if Debounce == false then
			Debounce = true
			player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player ~= nil then
				if connection then
					connection:Disconnect()

					if not opened and IsOpen.Value then
						opened = true
						for i = 1, 18 do
							script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
							script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
							game:GetService("RunService").Stepped:Wait()
						end
						wait(TimeAfterClose)
						for i = 1, 18 do
							script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
							script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
							game:GetService("RunService").Stepped:Wait()
						end
						opened = false

						wait(0.5)

						connection = Enter.Touched:Connect(OpenDoor1)
						Debounce = false
					end
				end
			end
		end
	end
end

-- Fires when the player trys to leave the building
function OpenDoor2(hit,player)
	if hit.Parent:FindFirstChild("Humanoid") then
		if Debounce == false then
			Debounce = true
			player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player ~= nil then
				if connection2 then
					connection2:Disconnect()

					if opened == false then
						opened = true
						for i = 1, 18 do
							script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
							script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
							game:GetService("RunService").Stepped:Wait()
						end
						wait(TimeAfterClose)
						for i = 1, 18 do
							script.Parent.LeftDoor:SetPrimaryPartCFrame(LeftHinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
							script.Parent.RightDoor:SetPrimaryPartCFrame(RightHinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
							game:GetService("RunService").Stepped:Wait()
						end

						opened = false

						wait(0.5)

						connection2 = Leave.Touched:Connect(OpenDoor2)
						Debounce = false
					end
				end
			end
		end
	end
end

connection = Enter.Touched:Connect(OpenDoor1)
connection2 = Leave.Touched:Connect(OpenDoor2)

For this solution it will disable any more functions untill the function u started is done

Second Solution

And another solution is to make it into 2 different scripts affect the same door if the Enter has been touched the script inside it should disable the leave door untill the door is done opening then it enables the script again

1 Like