function DeleteIdlePlane()for O,w in pairs(Planekit:GetChildren())do if w.Name=="\080\108\097\110\101"then w:Destroy()end end end function RegenMain()local O=PlaneClone:clone()O.Parent=Planekit O.Origin.Value=Planekit O:MakeJoints()return O end function RegeneratePlane(O)local w=game.Players:GetPlayerFromCharacter(O.Parent)if w then if Active then Active=false DeleteIdlePlane()for O=0,1,.2 do Main.Transparency=O wait()end if RegenTime>=1 then RegenGui.Parent=w.PlayerGui end wait(RegenTime)RegenGui.Parent=script local O=RegenMain()if EnterOnSpawn.Value then coroutine.resume(coroutine.create(function()repeat wait()until O.Welded.Value onPlaneWelded(w,O)end))end wait(WaitTime)for O=1,0,-0.2 do Main.Transparency=O wait()end Active=true end end end function onPlaneWelded(O,w)if w and O then if O.Character:findFirstChild("\084\111\114\115\111")then O.Character.Torso.CFrame=w.MainParts.Seat.CFrame end end end Main.Touched:connect(RegeneratePlane)
--------------------------------------------------------
function DeleteIdlePlane() --This deletes any planes that aren't currently being used
	for _, v in pairs(Planekit:GetChildren()) do
		if v.Name == "Plane" then
			v:Destroy()
		end
	end
end

function RegenMain() --This function regens the plane
	local PlaneClone2 = PlaneClone:clone()
	PlaneClone2.Parent = Planekit
	PlaneClone2.Origin.Value = Planekit
	PlaneClone2:MakeJoints()
	return PlaneClone2
end

function RegeneratePlane(Part) --This is the main regenerating function
	local Player = game.Players:GetPlayerFromCharacter(Part.Parent) --This gets the player that touched it
	if Player then
		if Active then
			Active = false
			DeleteIdlePlane() --This activates the "DeleteIdlePlane" function
			for i = 0, 1, 0.2 do --This makes the button transparent
				Main.Transparency = i
				wait()
			end
			if RegenTime >= 1 then
				RegenGui.Parent = Player.PlayerGui --The regengui will be put into the player if the regentime is more than 1
			end
			wait(RegenTime)
			RegenGui.Parent = script --This puts the gui back in the script
			local PlaneClone2 = RegenMain()
			if EnterOnSpawn.Value then --If the EnterOnSpawn value is true...
				coroutine.resume(coroutine.create(function()
					repeat
						wait()
					until PlaneClone2.Welded.Value
					onPlaneWelded(Player, PlaneClone2) --This activates the "onPlaneWelded" function whenever the welded value changes
				end))
			end
			wait(WaitTime)
			for i = 1, 0, -0.2 do --This makes the button visible
				Main.Transparency = i
				wait()
			end
			Active = true
		end
	end
end

function onPlaneWelded(Player, Plane) --This function put you into the plane seat the moment the plane is welded
	if Plane and Player then --This checks to make sure there is a plane and a player
		if Player.Character:findFirstChild("Torso") then
			Player.Character.Torso.CFrame = Plane.MainParts.Seat.CFrame
		end
	end
end

Main.Touched:connect(RegeneratePlane) --This activates the "RegeneratePlane" function when the Main brick is touched
