Is there a way to reference instances, with absolutely no chances of errors?

Example, you need to require a module script, and you need to check if it’s actually there. Would you use :WaitForChild() or just use :FindFirstChild() and use an if statement?

Because I’ve tried using :FindFirstChild() and if statements but it just looks awful.

2 Likes

It depends on your situation. For example, when I’m making variables, I use WaitForChild.

local object = workspace:WaitForChild("Object")

If I’m wanting to know if something is there, I use FindFirstChild.

if character:FindFirstChild("Sitting") then
    --I know the player is sitting
end
1 Like

Also one more thing, would it be best to create remote events in a script, or have them already there?

I would rather have them created in ReplicatedStorage rather than have a script create each individual one. Although, I’m not sure about the performance differences.

Ok, thank you. That’s all. (30 characters)

1 Like

You can always make your own functions if you feel like it looks cleaner.

local function waitFor(parent, ...)
    for i = 1, select("#", ...) do
        parent = parent:WaitForChild((select(i, ...)))
    end
    return parent
end

local Animator = waitFor(character, "Humanoid", "Animator")
1 Like