Greetings! I'm working on a script that spawns portals in random locations, but they more often then not spawn very close together or intersecting. I tried to figure out whats going on but I can't quite figure out why.
local RetrievedTreasures = {}
local function CheckIntersection(Object, Treasures)
local Intersects = false
for _,v in pairs(Treasures) do
local radius = 2.5
if Object:GetPrimaryPartCFrame().p.Z < (v.WepPosZ + radius)
and Object:GetPrimaryPartCFrame().p.Z > (v.WepPosZ - radius)
and Object:GetPrimaryPartCFrame().p.Y < (v.WepPosY + radius)
and Object:GetPrimaryPartCFrame().p.Y > (v.WepPosY - radius) then
Intersects = true break
end
end
return Intersects
end
local function CreatePortal()
local Intersect = true
while Intersect do
--summon portal function
Intersect = CheckIntersection(Portal, RetrievedTreasures)
wait()
end
end
CreatePortal()
This function is supposed to sort through the values in table of logged portals and check if the new portal is within radius of an existing one. Putting a radius value of 4 or lower seems to work fine, but 5 or higher breaks it. The new portal just flashing over the place looking for a suitable spot.
Although my main problem is that that they will spawn intersecting or within radius.. Any ideas as to what I'm doing wrong here? Thanks in advance.

2 comments
I will give this a try. Thanks
Works like a charm. Thanks you.