Issue with Raycasting only returning when it overlaps with something unrelated to the Filter?

^^ video of my main issue, i am unable to select the “rigpart” after moving it

and here ^^ is the overlapping thing, id like to note also despite not being sure why, the overlap area is smaller than it used to be??? it used to be like, the entire player model??

anyway, my goal is for it to not do that, it should be hitting the “rigpart” no matter what, it works perfectly fine on the normal parts but acts so weird on these ones specifically? and i am completely unsure why. i have tried seperating the initial one raycast into 2 and setting them both each with a single filter rather than just swapping the filter on the single raycast and am having the same result, i tried searching around to see if anyone else had this issue (using google because i do not like this forum’s ui) and couldnt find anything. i tried changing the length of the ray and it didnt change anything. i tried setting the filter manually to each seperate part rather than all direct children of “RigFolder” and nothing changed, i am REALLY stumped on this one

code vv (excuse this horribleness it was a single raycast before and i was having this issue, i figured maybe it was a thing with setting the filter that was messing it up and so i basically just duped it and made a 2nd raycast and havent changed it back lol)

local UserInputService = game:GetService("UserInputService")

--player
local LocalPlayer = game:GetService("Players").LocalPlayer
local Player = LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local mouse = Player:GetMouse()

playername = Player.Name

--module
local ColorPickerModule = require(Player.PlayerScripts:WaitForChild("ColorPicker"))
local EditorfuncModule = require(Player.PlayerScripts:WaitForChild("EditorModule"))

--input
local Mouse = Player:GetMouse()


--clear on start
local Selected = {}
local rigSelected = {}


--param
local NormalRaycastParams = RaycastParams.new()
local RigRaycastParams = RaycastParams.new()


NormalRaycastParams.FilterType = Enum.RaycastFilterType.Include
RigRaycastParams.FilterType = Enum.RaycastFilterType.Include

NormalRaycastParams.FilterDescendantsInstances = {character:WaitForChild("Folder"), workspace.ENVIROMENT }
--folder and rigfolder are different places inside of character
RigRaycastParams.FilterDescendantsInstances = {character:WaitForChild("RigFolder")}



--i hate typing/copy pasting the whole thing
movehandle = Player.PlayerGui:WaitForChild("Handles").MoveHandles
sizehandle = Player.PlayerGui:WaitForChild("Handles").ScaleHandles
rigmove = Player.PlayerGui:WaitForChild("Handles").MoveHandlesRIG


xmhandle = movehandle.XmoveHandle
ymhandle = movehandle.YmoveHandle
zmhandle = movehandle.ZmoveHandle

rxmhandle = rigmove.XmoveHandle
rymhandle = rigmove.YmoveHandle
rzmhandle = rigmove.ZmoveHandle

xshandle = sizehandle.XscaleHandle
yshandle = sizehandle.YscaleHandle
zshandle = sizehandle.ZscaleHandle

rhandle = Player.PlayerGui:WaitForChild("Handles").RotateHandles.RotateArc
rigrot = Player.PlayerGui:WaitForChild("Handles").RotateHandlesRIG.RotateArc


rot = Player.PlayerGui.editorGUI.MAIN.PartProp.rotation

flipVerButt = Player.PlayerGui.editorGUI.MAIN.PartDelLink.partFlipVer
flipHorButt = Player.PlayerGui.editorGUI.MAIN.PartDelLink.partFlipHor
flipFWBWButt = Player.PlayerGui.editorGUI.MAIN.PartDelLink.partFlipFWBW

clonePartButt = Player.PlayerGui.editorGUI.MAIN.PartDelLink.clonePart



highlightall = workspace.Folder.EntireRigHighlight
righighlight = workspace.Folder.RigHighlight


highlight = workspace.Folder.Highlight


--theres a bunch of functions here that just hide/show some handles dw about it
--andddd text change in ui stuff
--none of this has ANYTHING with the raycast

rigmode = false
Player.PlayerGui.editorGUI.MAIN.rigEdit.MouseButton1Click:Connect(function()
	rigmode = not rigmode

if rigmode == true then
	

	
	
		Player.PlayerGui.editorGUI.MAIN.scalePart.Visible = false
		Player.PlayerGui.editorGUI.MAIN.PartDelLink.clonePart.Visible = false
		
		Player.PlayerGui.editorGUI.MAIN.rigEdit.Text = "Stop editing rig"
		highlight.Enabled = false
		righighlight.Enabled = true

		xmhandle.Visible = false
		ymhandle.Visible = false
		zmhandle.Visible = false

		rhandle.Visible = false

		xshandle.Visible = false
		yshandle.Visible = false
		zshandle.Visible = false

		highlightall.Adornee = character:WaitForChild("RigFolder")
		highlightall.Enabled = true
		
		
		
		if Player:GetAttribute("rigedittype") == "rotate" then
			
			RIGROT()
		else
			if Player:GetAttribute("rigedittype") == "move" then
				
				RIGMOV()
			else
				if Player:GetAttribute("rigedittype") == "choose" then
					
					RIGSELECT()
				end
			end
		end

else
	
		Player.PlayerGui.editorGUI.MAIN.rigEdit.Text = "Edit rig"
		highlight.Enabled = true
		righighlight.Enabled = false
		
		rxmhandle.Visible = false
		rymhandle.Visible = false
		rzmhandle.Visible = false

		rigrot.Visible = false
		
		Player.PlayerGui.editorGUI.MAIN.PartDelLink.clonePart.Visible = true
		
		Player.PlayerGui.editorGUI.MAIN.scalePart.Visible = true
		
		highlightall.Enabled = false
		NormalRaycastParams.FilterDescendantsInstances = {character:WaitForChild("Folder"), workspace.ENVIROMENT}
		
		
		if Player:GetAttribute("editorguitype") == "big" then

			BIG()

		else if Player:GetAttribute("editorguitype") == "rotate" then


				ROT()



			else if Player:GetAttribute("editorguitype") == "choose" then

					SELECT()


				else if Player:GetAttribute("editorguitype") == "move" then

						MOVE()


					end
				end
			end
		end
		
		
end
	
end)


--more changing attributes here

Player.PlayerGui.editorGUI.MAIN.select.MouseButton1Click:Connect(function()	
	if rigmode == true then
		Player:SetAttribute("rigedittype", "choose")
	else
		Player:SetAttribute("editorguitype", "choose" )
	end
end)

Player.PlayerGui.editorGUI.MAIN.Movepart.MouseButton1Click:Connect(function()	
	if rigmode == true then
		Player:SetAttribute("rigedittype", "move")
	else
		Player:SetAttribute("editorguitype", "move" )
	end
end)

Player.PlayerGui.editorGUI.MAIN.scalePart.MouseButton1Click:Connect(function()	
	Player:SetAttribute("editorguitype", "big" )
end)

Player.PlayerGui.editorGUI.MAIN.Rotatepart.MouseButton1Click:Connect(function()	
	if rigmode == true then
		Player:SetAttribute("rigedittype", "rotate")
	else
		Player:SetAttribute("editorguitype", "rotate" )
	end
end)


Player:GetAttributeChangedSignal("rigedittype"):Connect(function()
	if Player:GetAttribute("rigedittype") == "move" then
		RIGMOV()
	else if Player:GetAttribute("rigedittype") == "rotate" then
			RIGROT()
		else if Player:GetAttribute("rigedittype") == "choose" then
				RIGSELECT()
			end
		end
	end
end)



Player:GetAttributeChangedSignal("editorguitype"):Connect(function()
		
		if Player:GetAttribute("editorguitype") == "big" and rigmode == false then
			BIG()

		else if Player:GetAttribute("editorguitype") == "rotate" and rigmode == false then
					ROT()
					
					
			else if Player:GetAttribute("editorguitype") == "choose" and rigmode == false then

					SELECT()
				else if Player:GetAttribute("editorguitype") == "move" and rigmode == false then
						
						MOVE()
							
					end
				end
			end
		end

	
	
end)


--ok main code time

Mouse.Button1Down:Connect(function()
	if Player.PlayerGui.editorGUI.Enabled then
		
			if rigmode == true then
				
				
			RigRaycastResult = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 250, RigRaycastParams)
			print(RigRaycastResult)
			print(RigRaycastParams)

			if RigRaycastResult then
				RigRaycastHit = RigRaycastResult.Instance




				if Player:GetAttribute("rigedittype") == "choose" and rigmode == true then

					highlight.Enabled = false
					righighlight.Enabled = true

					
						local raycastModel = RigRaycastHit:FindFirstAncestorOfClass("Model")
						rigSelected = {RigRaycastHit}
						print(RigRaycastHit)
						righighlight.Adornee = RigRaycastHit


						normalModelUUID = RigRaycastHit.Name
						rigname = tostring(RigRaycastHit.Name.. " - RIGGPART")				

						Player.PlayerGui.editorGUI.MAIN.PartDelLink.Visible = true
						Player.PlayerGui.editorGUI.MAIN.PartProp.Visible = true
						Player.PlayerGui.editorGUI.MAIN.PartProp.UUID.Text = normalModelUUID


						Player.PlayerGui.editorGUI.MAIN.PartProp.UserGivenName.Text = rigname
						Player.PlayerGui.editorGUI.MAIN.PartProp.UserGivenName.TextEditable = false
						Player.PlayerGui.editorGUI.MAIN.PartProp.PartType.Text = "RIGPART (this controls a motor6D)"

						game.ReplicatedStorage.sendRaycast:FireServer(RigRaycastHit)

						for index,item in workspace:FindFirstChild(Player.Name).RigFolder:GetChildren() do -- Iterates through provided object
							if item.ClassName == "Motor6D" then

								if item.Part1 == RigRaycastHit then -- if there is a Attribute with a specific value
									rigweld = item
								end
							end
						end

					rxmhandle.Adornee = RigRaycastHit
					rymhandle.Adornee = RigRaycastHit
					rzmhandle.Adornee = RigRaycastHit


						Player.PlayerGui.editorGUI.MAIN.PartProp.position.XPOSTEX.Text = rigweld.C0.Position.X
						Player.PlayerGui.editorGUI.MAIN.PartProp.position.YPOSTEX.Text = rigweld.C0.Position.Y
						Player.PlayerGui.editorGUI.MAIN.PartProp.position.ZPOSTEX.Text = rigweld.C0.Position.Z
						--return whatever it was that was found
					else
						Selected = {}
						highlight.Adornee = nil

						colorpicker:Cancel()

						xmhandle.Adornee = nil
						ymhandle.Adornee = nil
						zmhandle.Adornee = nil

						rhandle.Adornee = nil

						xshandle.Adornee = nil
						yshandle.Adornee = nil
						zshandle.Adornee = nil


						Player.PlayerGui.editorGUI.MAIN.PartDelLink.Visible = false
						Player.PlayerGui.editorGUI.MAIN.PartProp.Visible = false
						Player.PlayerGui.editorGUI.MAIN.changeShapeUI.Visible = false
					end

					EditorfuncModule.SetAXIS()


					--move
					if rigweld then		
						originCF = rigweld.C0
					end

					moveIncrement = 0.001
					--CHANGE MOVEINC TO A TEXBOX

                                        --move is used in a later thing i didnt include in this as it is not relivent

			end
		else

		
		NormalRaycastResult = workspace:Raycast(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 250, NormalRaycastParams)
		print(NormalRaycastResult)
		print(NormalRaycastParams)

		if NormalRaycastResult then
			NormalRaycastHit = NormalRaycastResult.Instance

			
		
				
		if Player:GetAttribute("editorguitype") == "choose" and rigmode == false then
			
					highlight.Enabled = true
					righighlight.Enabled = false
				
				if NormalRaycastHit:GetAttribute("Editable") == not false then
					local raycastModel = NormalRaycastHit:FindFirstAncestorOfClass("Model")
					Selected = {NormalRaycastHit}
					print(NormalRaycastHit)
					highlight.Adornee = NormalRaycastHit
			
			if highlight:GetPropertyChangedSignal("Adornee") then
				colorpicker:Cancel()
			end
					

					Player.PlayerGui.editorGUI.MAIN.PartDelLink.setcolor.MouseButton1Click:Connect(function(player)
						colorpicker:Start()
							colorpicker:SetColor(highlight.Adornee.Color)
						lastcolor = highlight.Adornee.Color 
					end)
					
					colorpicker.Changed:Connect(function(player)
						print(colorpicker:GetColor())
						
						game.ReplicatedStorage.SYNCCOLOR:FireServer(highlight.Adornee, colorpicker:GetColor())
						
					end)
					
					colorpicker.Closed:Connect(function(player, confirmed)
						if confirmed == false then
							
						game.ReplicatedStorage.SYNCCOLOR:FireServer(highlight.Adornee, lastcolor)
							
						end
					end)
			
					normalModelUUID = NormalRaycastHit.Name
					normalItemUserSetName = NormalRaycastHit:GetAttribute("UserSetName")				
					normalPartType = NormalRaycastHit.ClassName

				Player.PlayerGui.editorGUI.MAIN.PartDelLink.Visible = true
				Player.PlayerGui.editorGUI.MAIN.PartProp.Visible = true
				Player.PlayerGui.editorGUI.MAIN.PartProp.UUID.Text = normalModelUUID
				

				

				Player.PlayerGui.editorGUI.MAIN.PartProp.UserGivenName.Text = normalItemUserSetName
				Player.PlayerGui.editorGUI.MAIN.PartProp.UserGivenName.TextEditable = true
				Player.PlayerGui.editorGUI.MAIN.PartProp.PartType.Text = normalPartType
			
					game.ReplicatedStorage.sendRaycast:FireServer(NormalRaycastHit)
			
					for index,item in workspace:FindFirstChild(Player.Name).Folder:GetChildren() do -- Iterates through provided object
						if item.ClassName == "Weld" then
						
							if item.Part0 == NormalRaycastHit then -- if there is a Attribute with a specific value
								weld = item
							end
						end
					end
					
					xmhandle.Adornee = NormalRaycastHit
					ymhandle.Adornee = NormalRaycastHit
					zmhandle.Adornee = NormalRaycastHit

					rhandle.Adornee = NormalRaycastHit

					xshandle.Adornee = NormalRaycastHit
					yshandle.Adornee = NormalRaycastHit
					zshandle.Adornee = NormalRaycastHit
					
					
					Player.PlayerGui.editorGUI.MAIN.PartProp.position.XPOSTEX.Text = weld.C1.Position.X
					Player.PlayerGui.editorGUI.MAIN.PartProp.position.YPOSTEX.Text = weld.C1.Position.Y
					Player.PlayerGui.editorGUI.MAIN.PartProp.position.ZPOSTEX.Text = weld.C1.Position.Z
					
				
				
					
					local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = weld.C1:GetComponents()

					local X = math.atan2(-m12, m22)
					local Y = math.asin(m02)
					local Z = math.atan2(-m01, m00)
					
					local realX = math.deg(X)
					local realY = math.deg(Y)
					local realZ = math.deg(Z)
				
					rot.XROTTEX.Text = math.round(realX)
					rot.YROTTEX.Text = math.round(realY)
					rot.ZROTTEX.Text = math.round(realZ)
					
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.XSCATEX.Text = highlight.Adornee.Size.X
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.YSCATEX.Text = highlight.Adornee.Size.Y
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.ZSCATEX.Text = highlight.Adornee.Size.Z


						--return whatever it was that was found
				else
			Selected = {}
			highlight.Adornee = nil
			
			colorpicker:Cancel()
			
					xmhandle.Adornee = nil
					ymhandle.Adornee = nil
					zmhandle.Adornee = nil

					rhandle.Adornee = nil

					xshandle.Adornee = nil
					yshandle.Adornee = nil
					zshandle.Adornee = nil

					
			Player.PlayerGui.editorGUI.MAIN.PartDelLink.Visible = false
			Player.PlayerGui.editorGUI.MAIN.PartProp.Visible = false
			Player.PlayerGui.editorGUI.MAIN.changeShapeUI.Visible = false
			end
		
					EditorfuncModule.SetAXIS()

				
				--move
				if weld then		
				originCF = weld.C1
				end
				
				moveIncrement = 0.001
				--CHANGE MOVEINC TO A TEXBOX			
				
				
				-- rotate
				
				local rotateIncrement = 1
				
				function round(number)
					return math.floor((number / rotateIncrement) + 0.5) * rotateIncrement
				end
				function AngleFromAxis(axis, r)
					local relativeAngle = math.rad(round(math.deg(r)))

					return axis == Enum.Axis.X and {relativeAngle, 0, 0} 
						or axis == Enum.Axis.Y and {0, relativeAngle, 0} 
						or axis == Enum.Axis.Z and {0, 0, relativeAngle}
				end
				

				rhandle.MouseDrag:Connect(function(axis, relativeAngle, delta)
					
					
					game.ReplicatedStorage.repPartRotate:FireServer(weld, originCF, CFrame.Angles(unpack(AngleFromAxis(axis, relativeAngle))))
					
					weld.C1 = originCF * CFrame.Angles(unpack(AngleFromAxis(axis, relativeAngle)))
					
					local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = weld.C1:GetComponents()

					local X = math.atan2(-m12, m22)
					local Y = math.asin(m02)
					local Z = math.atan2(-m01, m00)

					local realX = math.deg(X)
					local realY = math.deg(Y)
					local realZ = math.deg(Z)

					rot.XROTTEX.Text = math.round(realX)
					rot.YROTTEX.Text = math.round(realY)
					rot.ZROTTEX.Text = math.round(realZ)
				end)

				rhandle.MouseButton1Down:Connect(function()
					originCF = weld.C1
				end)
				
				
				--scale	
				
				local cframeAtMouseDown, sizeAtMouseDown, lastGoalSize
				

				local function toPositive(vector: Vector3)		-- for sizing, we use this to get the correct sizing. if you don't, the negative axes will scale improperly
					return Vector3.new(
						math.abs(vector.X),
						math.abs(vector.Y),
						math.abs(vector.Z)
					)
				end

				local function minimumVector(vector: Vector3) 	-- this function checks that the size is at least 0.001 which is the minimum size. 
					return Vector3.new(							-- if you remove this, you will have your part attempting to go into the negative size 
						math.max(vector.X, 0.001),				-- which obviously won't work but it'll result in the part moving backwards
						math.max(vector.Y, 0.001),
						math.max(vector.Z, 0.001)
					)
				end
				
				local function maximumVector(vector: Vector3)
					return Vector3.new(
						math.min(vector.X, 10),
						math.min(vector.Y, 10),
						math.min(vector.Z, 10)
						
					)
					
				end
				
				local function OnScaleMove(face, distance)
					

					
					local step = SnapToGrid(distance, moveIncrement)

					local beforecap = minimumVector(sizeAtMouseDown + toPositive(Vector3.fromNormalId(face)) * step)
					local goalSize = maximumVector(minimumVector(sizeAtMouseDown + toPositive(Vector3.fromNormalId(face)) * step))
					
					print(goalSize)
					
					
					game.ReplicatedStorage.repPartScale:FireServer(highlight.Adornee, goalSize)
					
					
					if lastGoalSize ~= goalSize then -- removes the part from positioning when the minimum size is reached, also prevents an unnecessary calculation
						weldinfo = cframeAtMouseDown * CFrame.new(Vector3.fromNormalId(face) * distance / 2) -- positioning is divided by 2 because it's only one face to be resized, not 2. if we don't divide, it will scale at double the rate
						game.ReplicatedStorage.repPartScaleFIX:FireServer(weld, weldinfo)
					end
					lastGoalSize = goalSize
					
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.XSCATEX.Text = highlight.Adornee.Size.X
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.YSCATEX.Text = highlight.Adornee.Size.Y
					Player.PlayerGui.editorGUI.MAIN.PartProp.scale.ZSCATEX.Text = highlight.Adornee.Size.Z
					
				Player.PlayerGui.editorGUI.MAIN.PartProp.position.XPOSTEX.Text = weld.C1.Position.X
				Player.PlayerGui.editorGUI.MAIN.PartProp.position.YPOSTEX.Text = weld.C1.Position.Y
				Player.PlayerGui.editorGUI.MAIN.PartProp.position.ZPOSTEX.Text = weld.C1.Position.Z
				end

				local function OnScaleBegin()
					cframeAtMouseDown = weld.C1
					sizeAtMouseDown = highlight.Adornee.Size
				end
				
				xshandle.MouseDrag:Connect(OnScaleMove)
				xshandle.MouseButton1Down:Connect(OnScaleBegin)
				yshandle.MouseDrag:Connect(OnScaleMove)
				yshandle.MouseButton1Down:Connect(OnScaleBegin)
				zshandle.MouseDrag:Connect(OnScaleMove)
				zshandle.MouseButton1Down:Connect(OnScaleBegin)
				


				
					end
				end
			end
		end
end)


thank you for anyone who actually looks at this.

update: after a lot of headaches and testing i have realised that this is the fault of the motor6Ds i was using. i was unaware they could not be moved as freely as welds. my duct tape solution now is just to force the player to move a tiny bit everytime they click in that mode to reset the collision, now i get to clean up all this awful code yayy

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