local e=script.Parent.Plane.Plane:clone()script.Parent.Plane.Plane.Cloned.Value,e.Cloned.Value=true,true script.Parent.Plane.Plane.Origin.Value=script.Parent local J=script.Parent.Regen local B=false local g=5 e.PrimaryPart=e.MainParts.Main local M=e:GetModelSize()local H=(e:GetModelCFrame()).p local h=H-M/2 local z=H+M/2 local X=Region3.new(h,z)local O=Instance.new("\083\099\114\101\101\110\071\117\105")O.Name="\082\101\103\101\110\071\117\105"local y=Instance.new("\070\114\097\109\101",O)y.Name="\077\101\115\115\097\103\101"y.Style=Enum.FrameStyle.RobloxRound y.Position=UDim2.new(.5,-150,.25,-15)y.Size=UDim2.new(0,300,0,30)local q=Instance.new("\084\101\120\116\076\097\098\101\108",y)q.Name="\077\115\103"q.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"q.TextColor3=Color3.new(1,1,1)q.Font=Enum.Font.ArialBold q.FontSize=Enum.FontSize.Size12 q.Position=UDim2.new(.5,0,.5,0)function getPassengers(e)local J={}local function B(e)for e,g in pairs(e:GetChildren())do if g:IsA("\083\101\097\116")or g:IsA("\086\101\104\105\099\108\101\083\101\097\116")then if g:findFirstChild("\083\101\097\116\087\101\108\100")and g.SeatWeld.Part1 then local e=game.Players:GetPlayerFromCharacter(g.SeatWeld.Part1.Parent)if e then table.insert(J,e)end end end B(g)end end B(e)return J end function deleteInactivePlanes()for J,B in pairs(script.Parent:GetChildren())do if B.Name==e.Name then local e=getPassengers(B)if#e==0 then B:remove()end end end end function regionIsClear()local e=game.Workspace:findPartsInRegion3(X,J,100)return#e==0 end function regenMain()local J=e:clone()J.Parent=script.Parent J:MakeJoints()end J.Touched:connect(function(e)if B then return end local M=game.Players:GetPlayerFromCharacter(e.Parent)if not M then return end B=true deleteInactivePlanes()for e=0,.5,.1 do J.Transparency=e wait()end J.Transparency=.5 while not regionIsClear()do wait(.5)if M and(M.Parent and M:findFirstChild("\080\108\097\121\101\114\071\117\105"))then O.Parent=M.PlayerGui end end O.Parent=nil regenMain()wait(g)for e=.5,0,-0.1 do J.Transparency=e wait()end J.Transparency=0 B=false end)


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)
