Is it alright to filter through all of workspace?

hey guys… im currently trying to use raycasting for some part particles but thats not the point right now, anyway like im thinkin i can use raycastparams to exclude all parts dont have collisions soo… is it alright if i go through ALL of the workspace’s descendants?? or will can it lag the game too much?

local raycastparams = RaycastParams.new()
			raycastparams.FilterType = Enum.RaycastFilterType.Exclude
			local ignoredstuff = {}
                        
			for i, v in pairs(workspace:GetDescendants()) do -- heres what i want help with. is it alright to do this??
				if v:IsA("BasePart") then
					if not (v.CanQuery == true and v.CanCollide == true) then
						table.insert(ignoredstuff, v)
					end
				end
			end
			raycastparams.FilterDescendantsInstances = ignoredstuff
			
			local ray = workspace:Raycast(startcframe.Position, Vector3.new(0, -1, 0), raycastparams)

It can lag based off how many parts there are,
You should be using CollisionGroup or CollectionService for exclusions, aswell having CanQuery off will prevent it from being in the Raycast.

1 Like
local CollectionService = game:GetService("CollectionService")

local function updateRaycastParams()
    local raycastParams = RaycastParams.new()
    raycastParams.FilterType = Enum.RaycastFilterType.Exclude
    raycastParams.FilterDescendantsInstances = CollectionService:GetTagged("NoRaycast")
    return raycastParams
end

-- Tag parts to ignore
for _, part in ipairs(workspace:GetDescendants()) do
    if part:IsA("BasePart") and not (part.CanQuery and part.CanCollide) then
        CollectionService:AddTag(part, "NoRaycast")
    end
end

-- Use the params
local params = updateRaycastParams()
local ray = workspace:Raycast(startCFrame.Position, Vector3.new(0, -1, 0), params)

FYI, if you turn CanQuery off for Parts, then Raycasts don’t detect them.

1 Like

ohh, i didnt know canquery can disable the part being able to be hit by rays, thanks. anyway i figured some stuff out because going thru all of workspace’s descendants DID indeed cause a good lag spike, so i now just go through a different folder with some other stuff that i need excluded. thanks anyway!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.