Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if a model is a child of a model?

Asked by 4 years ago

The question pretty much sums up: How to check if a model is a child of another model, with a server script?

Thanks for the Help!

0
you could try if script.Parent.ClassName == "Model"l then...Code...end Donut792 216 — 4y

1 answer

Log in to vote
2
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use the IsA class identifier metamethod. This allows you to pass an Instance through a conditional statement asking to compare it, or it's parent in this case' class type. Virtually, this can act as a form of verifying whether a certain Object is a child, of a specific Instance.

local myModel = workspace.Model

if (myModel.Parent:IsA("Model")) then
    print(myModel.Name.." Is a child of "..myModel.Parent.Name.."!")
end
Ad

Answer this question