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

Find First Child Usage?

Asked by 9 years ago
local found = script.Parent.Parent.Parent:FindFirstChild("Ioniser")
if found then
    script.Parent:destroy()
end

In this section of code, its supposed to look in script.Parent.Parent.Parent to find a model with the name Ioniser, and if it does, its going to delete the parent of the script.

In practice, I've noticed that it will run through with the destroy() command even though "Ioniser" is not in the directory I want it to be when the script will remove itself.

Is this the proper usage of the FindFirstChild command, or should I try something else?

1 answer

Log in to vote
0
Answered by
Xianon 105
9 years ago

Make sure 'found' is false, try this


local found = script.Parent.Parent.Parent:FindFirstChild("Ioniser") print(found.Name) if found then script.Parent:destroy() elseif found == false then print("found is false") end

This is not a fix, is a debug trick, check that your variables are setted right.

0
esleif lol NotSoNorm 777 — 9y
0
:| Xianon 105 — 9y
Ad

Answer this question