Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to identify whether or not a Part is apart of a Model?

I want to be able to drag parts and models with my mouse, but I need a more efficient way of distinguishing the two.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local down
local mtarget

function clickObj()
	if mouse.Target ~= nil then 
		mtarget = mouse.Target
		
		print(mtarget)
		down = true
		mouse.TargetFilter = mtarget
		print(mouse.TargetFilter)
	end
end
mouse.Button1Down:connect(clickObj) 

function mouseMove()
	if down and mtarget then
		 if mtarget.Parent:IsA("Model") then 
			local posX,posY,posZ = mouse.hit.X, mouse.hit.Y, mouse.hit.Z
			mtarget.Parent:MoveTo(Vector3.new(posX,posY,posZ))
		else 		
			print("WHHHYYY!?!") 	
			local posX,posY,posZ = mouse.hit.X, mouse.hit.Y, mouse.hit.Z
			mtarget.Position = Vector3.new(posX,posY,posZ)
		end
		
		
end
end
mouse.Move:connect(mouseMove) 

function mouseDown()
	down = false
	mouse.TargetFilter = nil
	
end
mouse.Button1Up:connect(mouseDown)

1 answer

local function isPartInModel(part)
	if not part then -- Make sure we don't run code if there isn't a part
	    print("Couldn't find part")
	    return false
	else -- There is a valid object
	    if part:IsA("Part") then -- Check if it's a 'part'
	        if not part.Parent then-- no Parent then it's false
	          print("The Part is not apart of a Model")
		      return false
	        else
	            if part.Parent:IsA("Model") then--if parent return true
	                print("Part is apart of a Model!")
			        return true
	            elseif part.Parent:IsA("Part") then
		--[[Check if part is in a part that's in a model
	         Run a recursive function to keep 
              checking Part's Parent's hierarchy--]]
	            end
	        end
	    end
	 end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.