I have a script that clones models into a plane and positions them in random locations(via a primary part), the problem is that sometimes the models collide/clip trough each other due to the randomness.
Is there a way to check if the parts in the latest cloned model are colliding with the parts of a previous one? so that if they are I can delete the model and try again with a new random location
local model1 = workspace:WaitForChild("Model1") --change to name of 1st model
for i, v in pairs(model1:GetDescendants()) do
if v:IsA("MeshPart") or v:IsA("Part") then
v.Touched:Connect(function(hit)
if hit:FindFirstAncestor("Model2") then --change to name of 2nd model
--do code
end
end)
end
end
I made this for someone else not too long back. It checks if a part of some model is touching another part, and then checks if that other part belongs to a model of some given name.
Model:GetBoundingBox() to get the space the model occupies
Use those values to create a region3 (by using the CFrame and Vector3 size to calculate the “corners” of the bounding box
Use the region3 to do WorldRoot:FindPartsInRegion3
You may have to google some stuff (like the math for step 2 if you’re unfamiliar with creating a region3) but overall I think this could be a relatively simple solution. You can also visually “create” the bounding box to help with this step, which you can see an example of on this page; Model | Roblox Creator Documentation
Ninja edit: I probably would not use touched, get touching parts, etc. because in my experience it’s unreliable if your parts are anchored, cancollidefalse, moved via CFrame, etc.