Door open but not close

I made a code so that many doors with the same name work individually with some allowed items and I did this in a serverscriptservice but when the doors open I give them to interact again and they do not close, what do I do?
Yes, it is done with remote event and everything works, what does not work is what I am explaining


my code here:

local evento = game.ReplicatedStorage.DoorFuntion.OpenDoors
local tween = game:GetService("TweenService")
local infodoor = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

evento.OnServerEvent:Connect(function(player, puerta)
	local access = puerta:FindFirstChild('clearances')
	local modulo = require(access)
	
	local door1 = puerta:FindFirstChild("door1")
	local door2 = puerta:FindFirstChild("door2")
	
	local open = puerta:FindFirstChild("open")
	
	local p1 =puerta:FindFirstChild("bpos1")
	local p2 = puerta:FindFirstChild("bpos2")
	
	local abrirdoor1 = {
		CFrame = p1.CFrame:ToWorldSpace(CFrame.new(0, 0, 0))
	}
	local abrirdoor2 = {
		CFrame = p2.CFrame:ToWorldSpace(CFrame.new(0, 0, 0))
	}
	
	local cerrardoor1 = {
		CFrame = door1.CFrame
	}
	local cerrardoor2 = {
		CFrame = door2.CFrame
	}

	local close1 = tween:Create(door1,infodoor,cerrardoor1)
	local close2 = tween:Create(door2,infodoor,cerrardoor2)
	
	local open1 = tween:Create(door1,infodoor,abrirdoor1)
	local open2 = tween:Create(door2,infodoor,abrirdoor2)

	
	local deb = false
	
	local character = player.Character
	for i, keys in pairs(player.Backpack:GetChildren(modulo)) do
		if modulo[keys.Name] == true then
			if open.Value == false then
				open1:Play()
				open2:Play()
				wait(1.1)
				open.Value = true
				break
			else
				close1:Play()
				close2:Play()
				wait(1.1)
				open.Value = false
				break
			end
		end
	end
end)
2 Likes

I don’t understand why you have “break” in the

if open.Value == false then 

statements.
Try removing them?

1 Like

because it is verifying many cards and I put the break so as not to repeat the opening animation

4 Likes

I solved it, I thought about using 4 different positions than the initials and it worked

3 Likes

One issue I spotted (may not be the actual issue) is that you haven’t implemented your debounce; unused variable. I think you may have forgotten to implement it.

With debounce:

local deb = false
if not deb then
	local character = player.Character
	for i, keys in pairs(player.Backpack:GetChildren(modulo)) do
		if modulo[keys.Name] == true then
        	deb = true
			if open.Value == false then
				open1:Play()
				open2:Play()
			else
				close1:Play()
				close2:Play()
			end

			wait(1.1)

       	 	open.Value = not open.Value
        	deb = false

        	break
		end
	end
end

You may also want to move a chunk of your script out of OnServerEvent, since you’re re-calculating the CFrames every time someone fires the event. This could cause performance issues too if someone spams the event, calling :FindFirstChild() a ton of times (and re-requiring a module). I would suggesting thinking of a different way to handle the doors.

3 Likes

I already solved it but thanks for the help, it serves as an example or another method to only solve it

3 Likes