Spawn System - How to check if area about to spawn item clear?

Hello,
I am trying to make a spawn system from a Gui. I have that working but I need a way to check if there is anything inside the area the item is about to spawn at. I have tried PartTouched but doesn’t work 100% of the time and causes items to just get flung across the map. I know there are other ways, I just don’t know what they exactly are and how to code them.

Any help is much appreciated
Many Thanks
NaweRBLX

3 Likes

To achieve this you can use GetTouchingParts. You will need to create a CanCollide false part that covers the area that the item will spawn in, ensuring it’s not intersecting with anything that is CanCollide true. You can then check the area to ensure the number of intersecting parts is 0 before spawning the item.

Here’s an example of how it could work for you:

local spawnArea = part -- The BasePart that covers the spawn area

function spawnItem()
	local touchingParts = spawnArea:GetTouchingParts()
	if #touchingParts == 0 then
		-- Spawn it
	else
		-- Something's blocking the spawn area
	end
end

spawnArea.Touched:Connect(function()end) -- Creates a TouchInterest so GetTouchingParts works

Hope this helps!

5 Likes

I’ll try it now to see if it works for me
Thank You!

Works perfectly, just what I needed.
Thank You!
NaweRBLX

2 Likes