Part Spawner limiter

Hello, I’m new to scripting and was wondering if there was a methotd to make that only one crate can spawn in a block, because when 2 spawns in the same location the player can’t interact with it.

That’s the script to make crates spawn.

local crate = game.ReplicatedStorage.Crate
local crateSpawnTable = crateSpawns:GetChildren()

local waitTime = 5

local maxCrate = #crateSpawnTable
local cratesSpawned = 0

function countCrates()
	cratesSpawned = 0
	for i, s in pairs(crateSpawnTable) do
		if s:FindFirstChild("Crates") then
			cratesSpawned += 1
	return cratesSpawned

function crateSpawner()

	while true do
		local amountOfCrates = countCrates()
		if amountOfCrates < maxCrate then
			local crateClone = crate:Clone()
			local randomSpawn
				randomSpawn = crateSpawnTable[math.random(1, #crateSpawnTable)]
			until not randomSpawn:FindFirstChild("Coin")

			crateClone.Parent = randomSpawn
			crateClone.CFrame = randomSpawn.CFrame + (0,3,0)
			print("spawned normal crate")			


Thanks anyway!

1 Like

you want to make only 1 crate spawn at a time or you want to make sure that they don’t spawn in each other

1 Like

Check if the crateSpawner() function has happened in each spawn, then make it not be able to spawn until a player picks up the crate

1 Like

just store the currentposition inside the crate then or use raycast

1 Like

That would be a better way of doing it. Probably going to require more scripting though

1 Like

no I mean just create a value inside a crate for first one it could be 1 and then in a loop check if there’s already 1

1 Like

Oh, sorry. I thought you were only talking about raycasting. This would be even better

1 Like

I want that in every spawner only one crate at time can spawn until a player pick it up