How do I Filter so InsideResults Only works with parts name Engine, Handle or HumanoidRootPart to prevent lag.
local ToucherPart = script.Parent["Meshes/Sphere"]
local SG = script:WaitForChild("ShipGravity")
local ID = script:WaitForChild("GravityID")
--Shuttle Addition
if (_G.all_Gateships == nil) then
_G["all_Gateships"] = {}
end
ALL = _G.all_Gateships
shared["all_Gateships"] = _G.all_Gateships
--Models Addition
if (_G.all_Models == nil) then
_G["all_Models"] = {}
end
ALLMODELS = _G.all_Models
shared["all_Models"] = _G.all_Models
function CloneAdd(part)
local Gravity = part.Parent:FindFirstChild(SG.Name)
if not Gravity then
SG:Clone().Parent = part.Parent
end
end
function CloneRemove(player)
local Gravity = player.Character:FindFirstChild(SG.Name)
if Gravity then
if Gravity.Value == SG.Value then
Gravity:Destroy()
end
end
end
function CloneAddShuttle(part)
local Gravity = part.Parent:FindFirstChild(SG.Name)
local ShuttleEngine = part.Parent:FindFirstChild("Engine")
if not Gravity then
SG:Clone().Parent = part.Parent
end
end
function CloneRemoveShuttle(ShuttleModel)
local Gravity = ShuttleModel:FindFirstChild(SG.Name)
local ShuttleEngine = ShuttleModel:FindFirstChild("Engine")
if Gravity then
if Gravity.Value == SG.Value then
Gravity:Destroy()
end
end
end
function CloneAddModel(part)
local Gravity = part.Parent:FindFirstChild(SG.Name)
local ModelHandle = part.Parent:FindFirstChild("Handle")
if not ModelHandle then return end
if not Gravity then
SG:Clone().Parent = part.Parent
end
end
function CloneRemoveModel(ModelForGrav)
local Gravity = ModelForGrav:FindFirstChild(SG.Name)
local ModelHandle = ModelForGrav:FindFirstChild("Handle")
if not ModelHandle then return end
if Gravity then
if Gravity.Value == SG.Value then
Gravity:Destroy()
end
end
end
while task.wait(0.5) do
--print ("Touching Zone Printing")
local InsideResults = workspace:GetPartsInPart(ToucherPart)
--local OutsideResults = workspace:GetPartsInPart(ToucherPart)
--print (InsideResults)
--print (OutsideResults)
local modeltable = {}
for _, part in pairs(InsideResults) do
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid and not modeltable[humanoid.Parent] then
modeltable[part.Parent] = true
local Gravity = part.Parent:FindFirstChild(SG.Name)
if not Gravity then
CloneAdd(part)
end
--print (part.Parent.Name.." Is Inside Zone")
end
local ShuttleEngine = part.Parent:FindFirstChild("Engine")
if ShuttleEngine and not modeltable[ShuttleEngine.Parent] then
modeltable[ShuttleEngine.Parent] = true
local Gravity = part.Parent:FindFirstChild(SG.Name)
if not Gravity then
CloneAddShuttle(part)
end
--print (part.Parent.Name.." Is Inside Zone")
end
local ModelHandle = part.Parent:FindFirstChild("Handle")
if ModelHandle and not modeltable[ModelHandle.Parent] then
modeltable[ModelHandle.Parent] = true
local Gravity = part.Parent:FindFirstChild(SG.Name)
if not Gravity then
CloneAddModel(part)
end
--print (part.Parent.Name.." Is Inside Zone")
end
--print (modeltable)
end
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
local character = player.Character
if character and not modeltable[character] then --if character and not modeltable[character] then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local Gravity = player.Character:FindFirstChild(SG.Name)
if Gravity then
CloneRemove(player)
end
--print (player.Character.Name.." Is Outside Zone")
end
end
end
for i = 1, #ALL do
local ShuttleModel = ALL[i].Model
if ShuttleModel and not modeltable[ShuttleModel] then --if character and not modeltable[character] then
local Gravity = ShuttleModel:FindFirstChild(SG.Name)
if Gravity then
CloneRemoveShuttle(ShuttleModel)
end
--print (ShuttleModel.Name.." Is Outside Zone")
end
end
for i = 1, #ALLMODELS do
local ModelForGrav = ALLMODELS[i]
if ModelForGrav and not modeltable[ModelForGrav] then --if character and not modeltable[character] then
local Gravity = ModelForGrav:FindFirstChild(SG.Name)
if Gravity then
CloneRemoveModel(ModelForGrav)
end
--print (ModelForGrav.Name.." Is Outside Zone")
end
end
-- Clearing Table
-------------------
modeltable = {}
-------------------
end

10 comments
How do I add Engine, HumanoidRootPart and handles to the Filter Descendants Array, that's the part I am stuck on
?
I cant see how to use this: https://create.roblox.com/docs/reference/engine/datatypes/RaycastParams
I know i need to use this: FilterDescendantsInstances . But i dont get how to scan the workspace and add to that table the named parts i need.
what are you trying to do?
https://devforum.roblox.com/t/introducing-overlapparams-new-spatial-query-api/1435720
In order to use FilterDescendantsInstances it needs a table to ignore Parts etc, I need a way to loop through the workspace and find All Parts with the name Handle, Engine or HumanoidRootPart, and insert them to that table.
first use the Whitelist FilterType then loop through a folder or the path where those files where located if you dont know loop through workspace with getdescendants but i dont recommend this bc this causes alot of lag now that you got the table of it you can do
for Index,Value in pairs(Table) do if Value.Name == "Handle" or Value.Name == "Engine" or Value.Name == "HumanoidRootPart" then table.insert(IgnoreTable,Value) end end
i've edited the script with the Getinbounds setup