Spawncheck system?

Hi, I have a naval game with a carrier + plane spawns.

Recently, people have reported a bug where the planes would stack at the same spawn location if it’s not empty:

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.

g_zsn recommended that I create a spawn check where the aircraft would not spawn if the regen area was obstructed.

How can I do this? I don’t need any code, but any thoughts on how I should create a check for spawning?

Use Region3d
Go to the racing game template, and look in the script
workspace > Track Structures > CarSpawners > SpawnPad > RespawnCar > Analyzer

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
2 Likes