For example, lets say I dropped a part on a model. I want it to tell me if a specific part is in there or not. (I do not want to use getDecendents() because its not going to work in this situation). I haven't posted any code because I don't know what to do.
To clarify this question, I want to check if a specific int value is in the model that the part touched, but i can't use getDecendents because there is going to be multiple models with the same name.
Addition
So whipped up a script using you're help guys, but it says workspace.d.Script:8: attempt to index nil with 'GetDecendents' what is wrong now?
local part = script.Parent part.Touched:Connect(function() local par = part:GetTouchingParts() local model = par.Parent local z = model:GetDecendents() print(z) end)
Yes, you can check using loops or if you specifically know the name you can check it through an index. Also, your objective is not quite clear. can you explain more because you can drop an object but it will most likely end up in the workspace?
Well if you want to check for example you may do something like
if object:FindFirstChild("ObjNameHere") then -- Do code end
I don't understand your answer but I think you mean checking a part is in a model, then you should be using IsDescendantOf().
Lets say if a part is inside a model, you want to check if the part is inside the model or not, this example line will print true after you ran the code in that case.
print(Part:IsDescendantOf(Model))
If I'm not wrong, I think you meant that if there is a few model in the workspace and you want to check the one model that have a specific part in it, then this line of code will help.
for _, model in pairs(workspace:GetChildren()) if model:FindFirstChild("SpecialPart") then print(model.Name) end end
Result here or use this link: https://imgur.com/a/NO1xyrY (I'm using parts for the example)
If the model's parent aren't in workspace and the models have different parent, then you should be using workspace:GetDescendants() instead of workspace:GetChildren(). But if all of the models have the same parent, consider doing :GetChildren() but instead of using workspace, use the pathway of the models' parent.
Well if you want to run a function when a part touches another part, use this code:
local Part = workspace.Part local AnotherPart = workspace.AnotherPart AnotherPart.Touched:Connect(function(Hit) if Hit == Part then print("Part touched AnotherPart") end end)
Next time please explain your question better because it's kinda confusing