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

How do I go about using FindFirstChild() in a different script for an instance?

Asked by 4 years ago
Edited 4 years ago

From a different script is there a way to use FindFirstChild() or WaitForChild() after creating a part with an instance?

Or a script that waits for a part to be created?

If the part is created then do something.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I am not very good at scripting but this is what I would do:

local brick = Instance.new("Part")
brick.Name = "Brick"
brick.Parent = workspace

if game.Workspace:WaitForChild("Brick") then
   --Do what you want here
end

If this helped at all please accept this answer.

Ad
Log in to vote
0
Answered by 4 years ago

Try this

-- Finds it
local a = Instance.new("Part")
a.Name = "A Part"
a.Parent = game.Workspace

if game.Workspace:FindFirstChild(a) then
   --Lol
end

or this

-- Waits for it
local a = Instance.new("Part")
a.Name = "A Part"
a.Parent = game.Workspace
local b = game.Workspace:WaitForChild(a.Name)

if b then
   --Lol
end

Answer this question