How do i make a ray that can only detect water?

the title pretty much explains it. how to make a ray that only detects water?
i have tried this so far:

local origin = script.Parent.Parent.PrimaryPart.Position
	local destination = script.Parent.Parent.PrimaryPart.Position -,script.Parent.Parent.PrimaryPart.Size.Y,0)
	local direction = destination - origin
	local params =
	params.FilterType = Enum.RaycastFilterType.Whitelist
	params.FilterDescendantsInstances = {}
	params.IgnoreWater = false
	local results = workspace:Raycast(origin,direction,params)

but it doesnt return anything

1 Like

I believe direction needs to be:

local direction = (destination-origin).Unit

still doesnt work. also im not getting any errors

You need to whitelist Workspace.Terrain and then check the return Material for water.

1 Like