How do i findfirstchild but instead of a name its a type of instance?

i have a script that needs to go through a frame’s children and find a model
Every frame has a diffrent model, and i cant do “Name” i have to do sum like
:FindFirstChildThatIsA(“Model”) or somethin like that. idk if that exists but i need it
Thanks!

2 Likes

Simple, just use:

:FindFirstChildWhichIsA()

ok thank you so much!
do i just put the instance type like (Instance) or like (“Instance”)

You put it as a string, so for example if you’re trying to find a Model inside a Folder, you’d do:

local Folder = workspace.Folder
local Model = Folder:FindFirstChildWhichIsA("Model")

if Model then
 -- do whatever
end

Also, just like :FindFirstChild(), :FindFirstChildWhichIsA() has an optional parameter for if you’d like it to be recursive and search through all descendants.

1 Like

i jsut got

print(object:FindFirstChildWhichIsA("Model").Name)

and i go the error
“Attampt to index nil with name”

Wait i found the issue i think.

1 Like

now i gotta learn ho to use tables and put instances in them, can you help with that?

1 Like

Check out these topics:

And I suggest learning about table.insert() as well!

1 Like

i cant find anything on how to add what im trying to add to a table, so im going to make a devforum post for it.

1 Like
local instanceTable = {}
local object --your object

if object:FindFirstChildWhichIsA("Model") then
	for i,v in object:GetChildren()
		if v:IsA("Model") then
			table.insert(instanceTable, v)
		end
	end
end

pretty sure this would work (i had to code this with 1 hand since my other one is fractured)

1 Like

oh im sorry mans, what happened to ur hand?

1 Like

I fractured it a week ago skateboarding and only now just found out its fractured yesterday via an xray. (this is off topic though)

im sorry mans, i hope it heals. (idk if fractures heal)

1 Like

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