I’ve been collaborating on a project for some time now with some others and we’re having difficulty trying to find a way to see if any of the parents have humanoids in them and if so deny gathering access by a player (it’s a survival game so players are given gather tools). We thought FindFirstAncestorWhichIsA would be a solution but instead it’s function appears to just be an alternative to GetDescendants (or maybe I’m misunderstanding).
Basically in a nutshell tools are able to be gathered and disarmed when another player tries to gather the parts to them and we are trying to prevent this.
Either way we could use some help.
Code in question:
--Anything with a humanoid in its parents should not be gatherable
local humanoid = part:FindFirstAncestorWhichIsA("Humanoid")
if humanoid then
return false
end
The FindFirstAncestorWhichIsA method does return the first ancestor of an object in the tree that matches a given type, so using it to check if there’s a humanoid somewhere in the ancestor chain of the part in question should do the trick. If it’s returning unexpected results, it might be helpful to check if there might be some other issue with the code so you can narrow down the problem a bit more.
No, this won’t work like that. FindFirstAncestorWhichIsA returns anything only if the instance is parented to that object. Since you said that you want to find Ancestor with humanoid, we will need a different approach.
local model = part:FindFirstAncestorWhichIsA("Model") --since the humanoid should always be parented to model
if model then
local humanoid = model:FindFirstAncestorWhichIsA("Humanoid")
if humanoid then
return false
end
end