local T=false script.Parent.Touched:Connect(function(N)local e=N.Parent:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if e~=nil and script.Parent.CanCollide==true then local E local Z=game.Players:GetPlayerFromCharacter(N.Parent)if Z==nil and T==false then T=true E=e.WalkSpeed wait(.001)e.WalkSpeed=0 script.Parent.Unlock:Play()wait(1.1)script.Parent.Open:Play()script.Parent.Transparency=.25 script.Parent.CanCollide=false wait(1)e.WalkSpeed=E wait(1)T=false end end end)

local opening = false --This creates a bool to check if the door is opening.
script.Parent.Touched:Connect(function(hit) --This detects a touch on the door.
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") --This identifies the humanoid.
	if humanoid ~= nil and script.Parent.CanCollide == true then --This checks if a character touched the door and the door is closed.
		local humanoidwalkspeed --This creates a value to save the walk speed of the humanoid.
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) --This finds a player in the server.
		if player == nil and opening == false then --This ensures that there is no connected player to the character and that the door isn't opening yet.
			opening = true --This ensures that the script does not repeat the currently running code.
			humanoidwalkspeed = humanoid.WalkSpeed --This saves the current walk speed of the humanoid.
			wait(0.001) --This gives the script time to completely save the humanoid's current walk speed.
			humanoid.WalkSpeed = 0 --This stops the humanoid from walking.
			script.Parent.Unlock:Play() --This plays the "Door Knob" sound.
			wait(1.1) --There is a delay for opening the door.
			script.Parent.Open:Play() --This plays the door open sound.
			script.Parent.Transparency = 0.25 --This causes the door to be slightly transparent.
			script.Parent.CanCollide = false --This causes the door to stop colliding.
			wait(1) --The NPC will delay before walking through the door.
			humanoid.WalkSpeed = humanoidwalkspeed --This resets the humanoid walk speed to the original.
			wait(1) --This gives the NPC time to stop touching the door.
			opening = false --This allows the script to run the code again as long as the door is closed.
		end
	end
end)
