local q=script.Parent.Plane.Plane:clone()script.Parent.Plane.Plane.Cloned.Value,q.Cloned.Value=true,true script.Parent.Plane.Plane.Origin.Value=script.Parent local U=script.Parent.Regen local j=false local Z=5 q.PrimaryPart=q.MainParts.Main local K=q:GetModelSize()local m=(q:GetModelCFrame()).p local H=m-K/2 local t=m+K/2 local A=Region3.new(H,t)local N=Instance.new("\083\099\114\101\101\110\071\117\105")N.Name="\082\101\103\101\110\071\117\105"local o=Instance.new("\070\114\097\109\101",N)o.Name="\077\101\115\115\097\103\101"o.Style=Enum.FrameStyle.RobloxRound o.Position=UDim2.new(.5,-150,.25,-15)o.Size=UDim2.new(0,300,0,30)local a=Instance.new("\084\101\120\116\076\097\098\101\108",o)a.Name="\077\115\103"a.Text="\065\119\097\105\116\105\110\103 \097\114\101\097 \116\111 \098\101 \099\108\101\097\114 \102\111\114 \114\101\103\101\110\101\114\097\116\105\111\110 \116\111 \099\111\110\116\105\110\117\101"a.TextColor3=Color3.new(1,1,1)a.Font=Enum.Font.ArialBold a.FontSize=Enum.FontSize.Size12 a.Position=UDim2.new(.5,0,.5,0)function getPassengers(q)local U={}local function j(q)for q,Z in pairs(q:GetChildren())do if Z:IsA("\083\101\097\116")or Z:IsA("\086\101\104\105\099\108\101\083\101\097\116")then if Z:findFirstChild("\083\101\097\116\087\101\108\100")and Z.SeatWeld.Part1 then local q=game.Players:GetPlayerFromCharacter(Z.SeatWeld.Part1.Parent)if q then table.insert(U,q)end end end j(Z)end end j(q)return U end function deleteInactivePlanes()for U,j in pairs(script.Parent:GetChildren())do if j.Name==q.Name then local q=getPassengers(j)if#q==0 then j:remove()end end end end function regionIsClear()local q=game.Workspace:findPartsInRegion3(A,U,100)return#q==0 end function regenMain()local U=q:clone()U.Parent=script.Parent U:MakeJoints()end U.Touched:connect(function(q)if j then return end local K=game.Players:GetPlayerFromCharacter(q.Parent)if not K then return end j=true deleteInactivePlanes()for q=0,.5,.1 do U.Transparency=q wait()end U.Transparency=.5 while not regionIsClear()do wait(.5)if K and(K.Parent and K:findFirstChild("\080\108\097\121\101\114\071\117\105"))then N.Parent=K.PlayerGui end end N.Parent=nil regenMain()wait(Z)for q=.5,0,-0.1 do U.Transparency=q wait()end U.Transparency=0 j=false end)
-- Using the FindPartsInRegion3 API, this regen is "smart" and will NOT regenerate if something is in the way.
-- If something IS in the way, the script will wait for the area to be clear.

local plane = script.Parent.Plane.Plane:clone()
script.Parent.Plane.Plane.Cloned.Value, plane.Cloned.Value = true, true
script.Parent.Plane.Plane.Origin.Value = script.Parent
local regen = script.Parent.Regen
local active = false
local downtime = 5 -- This is the only thing you should edit in any script in this plane kit. Every other piece of code should be left alone

plane.PrimaryPart = plane.MainParts.Main
local planeSize = plane:GetModelSize()
local planePos = plane:GetModelCFrame().p
local v0 = (planePos - (planeSize / 2))
local v1 = (planePos + (planeSize / 2))
local region = Region3.new(v0, v1) -- Creates a 3D space using two Vector3s

local gui = Instance.new("ScreenGui")
gui.Name = "RegenGui"
local f = Instance.new("Frame", gui)
f.Name = "Message"
f.Style = Enum.FrameStyle.RobloxRound
f.Position = UDim2.new(0.5, -150, 0.25, -15)
f.Size = UDim2.new(0, 300, 0, 30)
local t = Instance.new("TextLabel", f)
t.Name = "Msg"
t.Text = "Awaiting area to be clear for regeneration to continue"
t.TextColor3 = Color3.new(1, 1, 1)
t.Font = Enum.Font.ArialBold
t.FontSize = Enum.FontSize.Size12
t.Position = UDim2.new(0.5, 0, 0.5, 0)

function getPassengers(pln) -- Checks for other players in seats on the plane. If no one is on board, the plane will be marked as "inactive" and removed
	local plrs = {}
	local function scan(parent)
		for _, v in pairs(parent:GetChildren()) do
			if (v:IsA("Seat")) or (v:IsA("VehicleSeat")) then
				if (v:findFirstChild("SeatWeld")) and v.SeatWeld.Part1 then
					local plr = game.Players:GetPlayerFromCharacter(v.SeatWeld.Part1.Parent)
					if plr then
						table.insert(plrs, plr)
					end
				end
			end
			scan(v)
		end
	end
	scan(pln)
	return plrs
end

function deleteInactivePlanes()
	for _, v in pairs(script.Parent:GetChildren()) do
		if v.Name == plane.Name then
			local passengers = getPassengers(v)
			if #passengers == 0 then
				v:remove()
			end
		end
	end
end

function regionIsClear()
	local parts = game.Workspace:findPartsInRegion3(region, regen, 100)
	return (#parts == 0)
end

function regenMain()
	local p = plane:clone()
	p.Parent = script.Parent
	p:MakeJoints()
end

regen.Touched:connect(function(obj)
	if active then
		return
	end
	local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
	if not plr then
		return
	end
	active = true
	deleteInactivePlanes()
	for i = 0, 0.5, 0.1 do
		regen.Transparency = i
		wait()
	end
	regen.Transparency = 0.5
	while not regionIsClear() do
		wait(0.5)
		if plr and plr.Parent and (plr:findFirstChild("PlayerGui")) then
			gui.Parent = plr.PlayerGui
		end
	end
	gui.Parent = nil
	regenMain()
	wait(downtime)
	for i = 0.5, 0, -0.1 do
		regen.Transparency = i
		wait()
	end
	regen.Transparency = 0
	active = false
end)
