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
Use :GetPartBoundsInBox() and use overlaps params(basically RaycastParams but for GetPartBoundsInBox)
local ToucherPart = script.Parent["Meshes/Sphere"] local SG = script:WaitForChild("ShipGravity") local ID = script:WaitForChild("GravityID") local IgnoreTable = {} --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 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 local Params = OverlapParams.new() Params.FilterType = Enum.RaycastFilterType.Whitelist Params.FilterDescendantsInstances = IgnoreTable while task.wait(0.5) do --print ("Touching Zone Printing") local InsideResults = workspace:GetPartBoundsInBox(ToucherPart.CFrame,ToucherPart.Size,Params) --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
Workspace.ShipGravZone.ZoneGravity:270: invalid argument #1 to 'pairs' (table expected, got nil)