Hello Scripters,
I have a simple question to ask. I want to figure out if the part or instance is existing in the workspace if not to do something else
if Instance then
print('Is there')
else
print('Not there')
end
Hello Scripters,
I have a simple question to ask. I want to figure out if the part or instance is existing in the workspace if not to do something else
if Instance then
print('Is there')
else
print('Not there')
end
if(part:IsDescendantOf(workspace)) then
...
end
Part of wouldnât work for me because âpartâ doesnât exist, how would i go about that?
âpartâ is the instance you want to check. I added it not as a pre-defined value but instead a placeholder so that you could put your actual part there.
Thank you for checking, but I implemented :IsDescendantOf()
into my script but I want to check if a instance has existed yet or not
you could use pcall function (What it does it wont error if the Part doesnât exist)
pcall(function()
end)
Or FindFirstChild (Recommended)
if not game.Workspace:FindFirstChild("YourPart") then
end
I think what the op was trying to refer to was, they canât use âIsDescendantOfâ because the variable isnât defined?
Maybe they are looking for:
Workspace:FindFirstChild(Name)
I see. In that case you can use is ancestor of:
workspace:IsAncestorOf(part)
And if you really donât have the variable and just want to check if it is there you can use:
workspace:FindFirstChild("PartNameHere")
Yeah you are probably looking for âFindFirstChild().â
Yes, I thought he meant another thing as in the error was saying âpart doesnât existâ.
Another thing, if you wish it to be recursive you can always add the second parameter:
workspace:FindFirstChild("PartNameHere", true)
This will ensure that it will check all across workspace, even if it is inside a model/part.