How to get the entire model that the mouse is pointing at?

ROBLOX Studio’s mouse selects the entire model that you click on (unless alt is held).
I want to be able to select entire models with my mouse but mouse.Target only selects a specific part? How can I make it select an entire model and it’s descendants with one selection box like ROBLOX Studio does?

ROBLOX Studio:
791ca8147ae4b2782078c0f297aed7c9

set a primary part. On the model. Try that

I could set a primary part, but if this is an example tree?:

Of course checking what parent the part is of could give me the model, but I am looking for checking all the way up to the actual model.

Check if Mouse.Target:IsDescendantOf(“Model”)

IsDescendantOf checks all of the descendants till it gets you a model though? Cause if it checks only part.Parent then it’s not very helpful.

I don’t really understand how to use IsDescendantOf is what I mean xD

1 Like

Yes It does :

local Model = script.Parent.Parent

if script.Parent:IsDescendantOf(Model) then
	print("It is")
end

oh, the thing is model is not defined, the title of this question is how to get the model? If I already had the model it wouldn’t be a problem

You can use:

local Target = Mouse.Target -- Get's the mouse target

if Target:FindFirstAncestorWhichIsA("Model") then -- looks if there is a model that is an ancestor of the target
    -- do something
end
3 Likes

Yeah I guess that.

I was thinking of this:

if Target.Parent:IsA("Model") or Target.Parent.Parent:IsA("Model") then
			print("It is")
		else
			print("its not")
		end

But when I click the baseplate it prints: “it is.”

Edit:
Do what @VegetationBush did

Thanks for the help guys it was that simple lol

Need help with FindFirstAncestorWhichIsA could you help?

1 Like