I added a spawn cooldown to prevent planes from stacking, since I thought players would take a plane before they spawn in another.
Then, someone reported the same bug again, because nobody had taken the aircraft before regening, or it was a troll.
Actually it would be easier to just paste the script here:
local Analyzer = {}
local function findHighestModel(object, highestModel)
if object.Parent == game.Workspace then
return highestModel
end
if object.Parent:IsA("Model") then
highestModel = object.Parent
end
return findHighestModel(object.Parent, highestModel)
end
function Analyzer:FindCarAbovePart(part)
local region = Region3.new(Vector3.new(part.Position.X - part.Size.X / 2,
part.Position.Y,
part.Position.Z - part.Size.Z / 2),
Vector3.new(part.Position.X + part.Size.X / 2,
part.Position.Y + 20,
part.Position.Z + part.Size.Z / 2))
local partsInRegion = game.Workspace:FindPartsInRegion3(region, part, 100)
local seat = nil
for _, part in ipairs(partsInRegion) do
if part:IsA("VehicleSeat") or part:IsA("Seat") then
seat = part
break
end
end
if seat then
local parent = findHighestModel(seat, nil)
if parent then
return parent
else
local carModel = Instance.new("Model")
for _, part in ipairs(seat:GetConnectedParts(true)) do
part:Clone().Parent = carModel
end
return carModel
end
end
end
return Analyzer