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.
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