assuming most games use overlapparams and GetPartBoundsInBox or GetPartBoundsInRadius, if you want to prioritize certain models you can either use table.sort or a loop to check for tags/properties.
an example of a table.sort would be:
local Parts = workspace:GetPartBoundsInRadius(Position, Radius, OLP) -- assuming this returns player character body parts or the barrier part
local ReturnedDict = {}
local ReturnedList = {}
for _,Part in next, Parts do
local Parent = Part.Parent
if ReturnedDict[Parent] == true then continue end
ReturnedDict[Parent] = true
table.insert(ReturnedList,Parent)
end
table.sort(ReturnedList,function(Model1,Model2)
local Tag1,Tag2 = Model1:HasTag("Barrier"),Model2:HasTag("Barrier")
return Tag1 == true and Tag2 == false
end)
return ReturnedList
in this case, i sort the table after the parents have been gathered to place the barrier objects in the front (first table position). most of the time, this is convenient but could potentially be slower then the table scan i do below.
an example of a table scan would be:
local Parts = workspace:GetPartBoundsInRadius(Position, Radius, OLP) -- assuming this returns player character body parts or the barrier part
local ReturnedDict = {}
local ReturnedList = {}
local PriorityList = {}
for _,Part in next, Parts do
local Parent = Part.Parent
if ReturnedDict[Parent] == true then continue end
ReturnedDict[Parent] = true
local Barrier = Parent:HasTag("Barrier")
if Barrier == true then
table.insert(PriorityList,Parent)
else
table.insert(ReturnedList,Parent)
end
end
table.move(ReturnedList,1,#ReturnedList,#PriorityList+1,PriorityList)
return PriorityList
in this example, i am directly checking for the barrier tag in the parts loop and putting them in a priority list. after everything has been iterated through, i move the non-priority models to the end of the priority list and return the priority list so any barrier parts will always be hit first.
the methods you use will change depending on your code base, but using a tags system combined with proper overlapparameter usage will make your code much faster and easy to implement