I have this coin spawn system that spawns coins on a part by detecting the size of the part. But there are also other objects on that part and those coins are overlapping with each other. Is there any way to stop them from overlapping such as making a group of part names that it won’t spawn near?
This is my current script that spawns the coins
local coin = game.ServerStorage.exp-- Path to coin
local amountCoins = 0
local maxCoins = 20
while true do
task.wait()
if amountCoins >= maxCoins then continue end
local clone = coin:Clone()
clone.Parent = game.Workspace
local Baseplate = workspace.Baseplatep1
local Size = Baseplate.Size
local Pos = Baseplate.Position
local CoinHeight = 2 -- You can choose
local X,Y,Z = math.random(Pos.X - (Size.X/2), Pos.X + (Size.X/2)),Pos.Y +
CoinHeight,math.random(Pos.Z - (Size.Z/2), Pos.Z + (Size.Z/2))
local SpawnPos = Vector3.new(X,Y,Z)
clone.Position = SpawnPos
amountCoins += 1
clone.Destroying:Connect(function()
amountCoins -= 1
end)
task.wait(20)
end