local S=ACS_Storage:FindFirstChild("\068\111\111\114\115")local N=game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")local G=5 local p=nil function getNearest()local N=nil local p=G local H=Player.Character or Player.CharacterAdded:Wait()for S,G in pairs(S:GetChildren())do if G.Door:FindFirstChild("\075\110\111\098")~=nil then local S=(G.Door.Knob.Position-H.Torso.Position).magnitude if S<p then N=G p=S end end end return N end function Interact(S,N,H)if N~=Enum.UserInputState.Begin then return end local m=getNearest()local x=Player.Character or Player.CharacterAdded:Wait()if m==nil then return end if(m.Door.Knob.Position-x.Torso.Position).magnitude<=G then if m~=nil then if m:FindFirstChild("\082\101\113\117\105\114\101\115\075\101\121")then p=m.RequiresKey.Value else p=nil end Evt.DoorEvent:FireServer(m,1,p)end end end function GetNearest(S,N,G)local p local H=N for S,N in ipairs(S)do local m=(G.Position-N.Position).magnitude if m<H then p=N H=m end end return p end N:BindAction("\073\110\116\101\114\097\099\116",Interact,false,Enum.KeyCode.G)Evt.Rappel.PlaceEvent.OnClientEvent:Connect(function(S)local N=Instance.new("\065\108\105\103\110\079\114\105\101\110\116\097\116\105\111\110")N.Parent=S N.PrimaryAxisOnly=true N.RigidityEnabled=true N.Attachment0=Character.HumanoidRootPart.RootAttachment N.Attachment1=Camera.BasePart.Attachment end)print("\065\067\083 \049\046\055\046\053")

local DoorsFolder = ACS_Storage:FindFirstChild("Doors")
local CAS = game:GetService("ContextActionService")

local mDistance = 5
local Key = nil

function getNearest()
	local nearest = nil
	local minDistance = mDistance
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	for I,Door in pairs (DoorsFolder:GetChildren()) do
		if Door.Door:FindFirstChild("Knob") ~= nil then
			local distance = (Door.Door.Knob.Position - Character.Torso.Position).magnitude
		
			if distance < minDistance then
				nearest = Door
				minDistance = distance
			end
		end
	end
	--print(nearest)
	return nearest
end

function Interact(actionName, inputState, inputObj)
	if inputState ~= Enum.UserInputState.Begin then return end
	
	local nearestDoor = getNearest()
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	if nearestDoor == nil then return end
	
	if (nearestDoor.Door.Knob.Position - Character.Torso.Position).magnitude <= mDistance then
		if nearestDoor ~= nil then
			if nearestDoor:FindFirstChild("RequiresKey") then
				Key = nearestDoor.RequiresKey.Value
			else
				Key = nil
			end
			Evt.DoorEvent:FireServer(nearestDoor,1,Key)
		end
	end
end


function GetNearest(parts, maxDistance,Part)
	local closestPart
	local minDistance = maxDistance
    for _, partToFace in ipairs(parts) do
        local distance = (Part.Position - partToFace.Position).magnitude
        if distance < minDistance then
            closestPart = partToFace
            minDistance = distance
        end
   end
	return closestPart
end

CAS:BindAction("Interact", Interact, false, Enum.KeyCode.G)

Evt.Rappel.PlaceEvent.OnClientEvent:Connect(function(Parte)
	local Alinhar = Instance.new('AlignOrientation')
	Alinhar.Parent = Parte
	Alinhar.PrimaryAxisOnly = true
	Alinhar.RigidityEnabled = true
	Alinhar.Attachment0 = Character.HumanoidRootPart.RootAttachment
	Alinhar.Attachment1 = Camera.BasePart.Attachment
end)

print("ACS 1.7.5")
