car=script.Parent.Parent Base=car:FindFirstChild("\066\097\115\101")Left=car:FindFirstChild("\076\101\102\116")Right=car:FindFirstChild("\082\105\103\104\116")function MakeDoor(N,e,M,K)local s=Instance.new("\077\111\116\111\114",car)s.Name=N.Name.."\077\111\116\111\114"s.Part0=e s.Part1=N s.C0=K s.C1=M s.MaxVelocity=.05 e.CanCollide=true local V=false e.Touched:connect(function(N)if not V and(N.Parent and(N.Name=="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"and(game:GetService("\080\108\097\121\101\114\115")):GetPlayerFromCharacter(N.Parent)))then V=true e.CanCollide=false s.DesiredAngle=math.pi/3 wait(1.5)s.DesiredAngle=0 wait(.5)e.CanCollide=true V=false end end)end function MakeWeldDoor(N,e)local M=Instance.new("\077\111\116\111\114\054\068",car)M.Name=N.Name.."\077\111\116\111\114"M.Part0=e M.Part1=N M.C1=N.CFrame:inverse()*e.CFrame e.CanCollide=false end function GetCFrame(N)if N:IsA("\067\070\114\097\109\101\086\097\108\117\101")then return N.Value elseif N:IsA("\083\116\114\105\110\103\086\097\108\117\101")then local e=nil pcall(function()e=CFrame.new(N.Value:match("\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041\044\040\046\043\041"))end)return e end end for N,e in pairs(car:GetChildren())do if e:IsA("\077\111\116\111\114\054\068")then e:Destroy()end end for N,e in pairs(car:GetChildren())do if e:IsA("\066\097\115\101\080\097\114\116")and e.Name:find("\068\111\111\114\072\105\110\103\101")then local N=e.Name:match("\068\111\111\114\072\105\110\103\101\040\046\042\041")local M=car:FindFirstChild("\068\111\111\114"..N)if M then local N=M:FindFirstChild("\068\111\111\114\067\070\114\097\109\101")local K=M:FindFirstChild("\072\105\110\103\101\067\070\114\097\109\101")if N and K then local s=GetCFrame(N)local V=GetCFrame(K)if s and V then MakeDoor(e,M,V,s)else MakeWeldDoor(e,M)end else MakeWeldDoor(e,M)end end end end if Base then if Left then leftMotor=Instance.new("\077\111\116\111\114\054\068",car)leftMotor.Name="\076\101\102\116\077\111\116\111\114"leftMotor.Part0=Left leftMotor.Part1=Base leftMotor.C0=CFrame.new(-WheelSize/2-Left.Size.x/2,0,0)*CFrame.Angles(math.pi/2,0,-math.pi/2)leftMotor.C1=CFrame.new((Base.Size.x/2+Left.Size.x)+WheelSize/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)leftMotor.MaxVelocity=motorSpeed end if Right then rightMotor=Instance.new("\077\111\116\111\114\054\068",car)rightMotor.Name="\082\105\103\104\116\077\111\116\111\114"rightMotor.Part0=Right rightMotor.Part1=Base rightMotor.C0=CFrame.new(-WheelSize/2-Right.Size.x/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)rightMotor.C1=CFrame.new((-Base.Size.x/2-Right.Size.x)-WheelSize/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)rightMotor.MaxVelocity=motorSpeed end end

car = script.Parent.Parent

Base = car:FindFirstChild("Base")
Left = car:FindFirstChild("Left")
Right = car:FindFirstChild("Right")

function MakeDoor(hinge,door,hingeOffset,doorOffset)
	local doorMotor = Instance.new("Motor",car)
	doorMotor.Name = hinge.Name.."Motor"
	doorMotor.Part0 = door
	doorMotor.Part1 = hinge
	doorMotor.C0 = doorOffset
	doorMotor.C1 = hingeOffset
	doorMotor.MaxVelocity = 0.05
	door.CanCollide = true
	local doorDebounce = false
	door.Touched:connect(function(it)
		if not doorDebounce and it.Parent and it.Name == "HumanoidRootPart" and game:GetService("Players"):GetPlayerFromCharacter(it.Parent) then
			doorDebounce = true
			door.CanCollide = false
			doorMotor.DesiredAngle =  math.pi/3
			wait(1.5)
			doorMotor.DesiredAngle = 0
			wait(0.5)
			door.CanCollide = true
			doorDebounce = false
		end
	end)
end
function MakeWeldDoor(hinge,door)
	local doorMotor = Instance.new("Motor6D",car)
	doorMotor.Name = hinge.Name.."Motor"
	doorMotor.Part0 = door
	doorMotor.Part1 = hinge
	doorMotor.C1 = hinge.CFrame:inverse()*door.CFrame
	door.CanCollide = false
end

function GetCFrame(object)--we'll get a CFrame value out of a CFrameValue or a StringValue formatted like a CFrame
	if object:IsA("CFrameValue") then--if someone is using a CFrame value then we'll just pull the value directly
		return object.Value
	elseif object:IsA("StringValue") then--added functionality for this because I dislike interfacing with CFrame values
		local cframe = nil
		pcall(function()--using pcall because i'm lazy
			cframe = CFrame.new(object.Value:match("(.+),(.+),(.+),(.+),(.+),(.+),(.+),(.+),(.+),(.+),(.+),(.+)"))
			--if you print your CFrame and paste it into the string value, this will find that out and use it properly
		end)
		return cframe
	end
end

for _,h in pairs (car:GetChildren()) do
	if h:IsA("Motor6D") then--make sure we start with a blank slate
		h:Destroy()
	end
end

for _,i in pairs (car:GetChildren()) do
	if i:IsA("BasePart") and i.Name:find("DoorHinge") then-- found a door with regex!
		local DoorID = i.Name:match("DoorHinge(.*)")--haha regex is fun
		local MatchingDoor = car:FindFirstChild("Door"..DoorID)--can we use our regex powers to find a matching door?
		if MatchingDoor then-- yay we found one!
			local DoorCFrameValue = MatchingDoor:FindFirstChild("DoorCFrame")
			local HingeCFrameValue = MatchingDoor:FindFirstChild("HingeCFrame")
			if DoorCFrameValue and HingeCFrameValue then
				local doorCFrame = GetCFrame(DoorCFrameValue)
				local hingeCFrame = GetCFrame(HingeCFrameValue)
				if doorCFrame and hingeCFrame then
					MakeDoor(i,MatchingDoor,hingeCFrame,doorCFrame)
				else
					MakeWeldDoor(i,MatchingDoor)
				end
			else
				MakeWeldDoor(i,MatchingDoor)
			end
		end
	end
end

if Base then
	if Left then
		leftMotor = Instance.new("Motor6D", car)
		leftMotor.Name = "LeftMotor"
		leftMotor.Part0 = Left
		leftMotor.Part1 = Base
		leftMotor.C0 = CFrame.new(-WheelSize/2-Left.Size.x/2,0,0)*CFrame.Angles(math.pi/2,0,-math.pi/2)
		leftMotor.C1 = CFrame.new(Base.Size.x/2+Left.Size.x+WheelSize/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)
		leftMotor.MaxVelocity = motorSpeed
	end
	if Right then
		rightMotor = Instance.new("Motor6D", car)
		rightMotor.Name = "RightMotor"
		rightMotor.Part0 = Right
		rightMotor.Part1 = Base
		rightMotor.C0 = CFrame.new(-WheelSize/2-Right.Size.x/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)
		rightMotor.C1 = CFrame.new(-Base.Size.x/2-Right.Size.x-WheelSize/2,0,0)*CFrame.Angles(math.pi/2,0,math.pi/2)
		rightMotor.MaxVelocity = motorSpeed
	end
end
