Detect If Part Not Fully Onto Raycasted Part

I’m currently attempting to use raycasting again, and I’m unsure how to make it so if the raycast isn’t fully on a part, it won’t reposition the part that’s supposed to move to said raycast.

I’ve looked through said Documents and the Devforum itself and can’t find anything related that fits my needs, though I may not possibly be searching the correct terms.

local UserInputService, Players = game:GetService("UserInputService"), game:GetService("Players")
local CurrentCamera = workspace.CurrentCamera

local Params =
Params.FilterDescendantsInstances = {Players.LocalPlayer.Character, workspace:WaitForChild("Drag")} -- anything you want, for example the player's character, the ray filters through these
Params.FilterType = Enum.RaycastFilterType.Exclude -- choose exclude or include

local function RayResult(X, Y)
	local NewRay = CurrentCamera:ScreenPointToRay(X, Y) -- :ViewportPointToRay() is another choice
	return workspace:Raycast(NewRay.Origin, NewRay.Direction * 150, Params) -- 500 is how far to raycast

UserInputService.InputEnded:Connect(function(Input, Processed) -- not exactly a click, but like the end of a mouse press or tap
	if not Processed then
		local inputType = Input.UserInputType
		if inputType == Enum.UserInputType.Touch or inputType == Enum.UserInputType.MouseButton1 then
			local Results = RayResult(Input.Position.X, Input.Position.Y)
			workspace.Drag.Position = Results.Position
			workspace.Drag.CFrame =, workspace.Drag.Position + Results.Normal)
Image Example


Maybe try raycasting throught all of the 4 corners and if they all hit then place the image?