How can I make a raycast ignore everything except a part named plot

So im making plot stuff and i need the raycast to ignore everything and find the plot piece below it but im not sure howd i go about doing that.
Ignore everything except whats in the circle
image

PlacementEvent.OnServerEvent:Connect(function(Player,PreviewObject,ObjectCFrame)

	local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
	
	
	Object:SetPrimaryPartCFrame(ObjectCFrame)
	Object.Parent = game.Workspace
	
	wait(1)
	
	
	local mainp = Object.MainPart
	local startpos = mainp.Position
	local raydirection = Vector3.new(0,-100,0)
	
	local raycastresults = workspace:Raycast(startpos, raydirection)
	if raycastresults then
		local parthit = raycastresults.Instance
		print(parthit.name)
	end
end)
2 Likes
1 Like

So this is what you need:

local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = game.Workspace.Plots
RayParams.FilterType = Enum.FilterType.Whitelist

Pass that into the RayParams as the third argument to the Raycast

1 Like

RaycastParams should come in handy in this case.

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.Plots}
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.IgnoreWater = true

local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	if raycastResults then
		local parthit = raycastResults.Instance
		print(parthit.name)
	end
1 Like

Thanks i combined your answer with another guys answer so i couldnt give both you the solution sorry

2 Likes

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