Detect part with CanQuerry set to False

Setting canquerry to false helps improve performance of games with a but ton of parts which is why I have parts that have can collide, can touch and canquerry set to false, although I still want the player to be able to collide with these parts

The way I think about going with this is to check all parts bound in radius and make them collidable but of course that won’t work and I can’t seem to find a single good solution to this

Comment anything you know, I need a solution and I bet 2000 others also do :eye: :lips: :eye:

1 Like

Hello!

Create a script in ServerScriptService and try this:

function Touched(Part:Part): {Instance}
	local params = OverlapParams.new()
	params.FilterDescendantsInstances = {}
	params.FilterType = Enum.RaycastFilterType.Exclude
	
	local Parts = workspace:GetPartBoundsInBox(Part.CFrame, Part.Size, params)
	
	return Parts
end

local part = workspace:FindFirstChild("Part")

while wait() do
	local Parts = Touched(part)
	
	for _,hit in pairs(Parts) do
		--//if you need to get a player
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			print(plr.Name.." Touched Part")
		end
	end
end
1 Like

Doing that would actually result in worse performance than if you kept CanCollide set to true

What people mean when they say to turn off CanCollide, CanQuery and CanTouch is for parts that don’t need them to be on, as an example:

  • If you’re not using the part’s Touched or TouchEnded events, then CanTouch can be set to false
  • If the part is very small like a crumpled up piece of paper or a flower, then CanCollide doesn’t need to be set to true
  • If the part has CanCollide set to false and you don’t want raycasts to detect it, then turn off CanQuery

If you’re experiencing lag due to many parts within your game, then consider grouping them together into meshes using something like Blender

I also recommend you read this docs article to learn more about how to optimize:


@RobloxTim2001 Also, consider using streaming:

It helps quite a lot for games with large maps, but will require you to code a bit differently since Instances will no longer be guaranteed to be present on the client even after they’ve finished loading

This is a very bad idea. To do this, you’d most likely have to perform a function such as workspace:GetPartBoundsInBox() to detect if the character is intersecting a part’s hitbox on every step, which is very performance-heavy. Instead, I suggest you do the following:

  1. Set CanCollide, CanTouch, and CanQuery to false for all parts that do not require collision or raycast interactions, such as small decorations.

  2. Unfortunately, CanQuery cannot be disabled while CanCollide is set to true. If you want a raycast to ignore a part, while still maintaining it’s collisions, filter them out using RaycastParams

  3. If you want to improve performance, workspace.StreamingEnabled is a great solution that does not require any custom rendering code.

Content Streaming is certainly the way to go, and I would specifically recommend modifying the model’s Level of Detail. When the player walks a certain distance away, this property will convert the model into a look-alike mesh that isn’t as resource heavy as the original BaseParts.

Sorry for replying to everybody so late but I can see that everybody’s recommending streaming. I’ll play around with the settings but I’m sure it will still lag a lot . I will be replying back after the results : )

Well my conclusion is… Drum roll please :drum: :drum: :drum: :drum: :drum: :drum: :drum: :drum: :drum:

My script sucks, yes streaming did help a little, I looked and tried every single suggestion but it did not magically fix the problems. Thank you all for helping me, and for anyone looking for how to detect parts with CanQuerry set to false its simply impossible using the traditional ways. The only way I can come up with is having the parts stored inside an array there if said distance was to be as an example 20 studs away you enable CanQuerry but that would maybe worsn’ the performance

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