How to use OverlapParams?

The booth model on the other side is a copy and paste of this booth model, so everything is the same, including the script.

As you can see, Get PartsInPart ignores even though it’s different models and includes parts.
So I want to use OverlapParams to make parts are not included if it’s different models.

local toolEvent = ReplicatedStorage:WaitForChild("ToolEvent")

toolEvent.OnServerEvent:Connect(function(player, target, newCFrame)
	local originPosition = target.Position
	local testpart = TierModel.testpart

	if target and newCFrame then
		local partName = target.Name
		local playerValue = player:FindFirstChild(partName)

		if playerValue == nil then
			return false
		end

		if target.Name ~= playerValue.Name then
			return false
		end

		local originalCFrame = target.Position
		if target.Locked then
			return false
		end
		target.Position = newCFrame

		local params = OverlapParams.new()
		params.FilterDescendantsInstances = {target}
		params.FilterType = Enum.RaycastFilterType.Include

		local partsInTestPart = workspace:GetPartsInPart(testpart, params)
		local targetIncluded = false

		for _, part in ipairs(partsInTestPart) do
			if part == target then
				targetIncluded = true
				break
			end
		end

		if not targetIncluded then
			target.Position = originalCFrame
		end
	end
end)

But I have no idea how to use OverlapParams.
I did this for now… it doesn’t work. Still other models include parts.

Can you solve this problem? please…

Parts from different models are excluded properly:

local toolEvent = ReplicatedStorage:WaitForChild("ToolEvent")

toolEvent.OnServerEvent:Connect(function(player, target, newCFrame)
	local originPosition = target.Position
	local testpart = TierModel.testpart

	if target and newCFrame then
		local partName = target.Name
		local playerValue = player:FindFirstChild(partName)

		if playerValue == nil then
			return false
		end

		if target.Name ~= playerValue.Name then
			return false
		end

		local originalCFrame = target.Position
		if target.Locked then
			return false
		end
		target.Position = newCFrame

		local params = OverlapParams.new()
		params.FilterDescendantsInstances = {target.Parent} -- Exclude the target's parent model
		params.FilterType = Enum.RaycastFilterType.Exclude -- Exclude the specified instances

		local partsInTestPart = workspace:GetPartsInPart(testpart, params)
		local targetIncluded = false

		for _, part in ipairs(partsInTestPart) do
			if part == target then
				targetIncluded = true
				break
			end
		end

		if not targetIncluded then
			target.Position = originalCFrame
		end
	end
end)
1 Like


Thank you so much, but this filters itself. Is there any other way?

Here’s an alternative approach that uses a different collision detection method too

2 other ways

  1. Use Region3 to create a bounding box around the testpart.
  2. Use workspace:FindPartsInRegion3WithIgnoreList to find parts within this region, excluding the target part and its parent model.
1 Like