I don't completely understand the actual differences when it comes to using findFirstChild and the square brackets, per say:
local part = Instance.new("Part").Parent = game.Workspace local a = game.Workspace:findFirstChild("Part") local b = game.Workspace["Part"] -- Using an if statement to check if this exists doesn't work. local c = game.Workspace.Part
When should I use which?
-Use the "." when using a single-word part.
-Use when using a multiple-word part.
-Use FindFirstChild when you aren't sure of the existence of the part or if you want to find a descendant, not just a child.
Example of FindFirstChild for finding descendants:
local model = Instance.new("Model", workspace) Instance.new("Part", model) print(Workspace:FindFirstChild("Part", true).Parent.Name) --Prints Model, because of "true" argument.
Example of FindFirstChild if statement:
if Workspace:FindFirstChild("Articulating") and Workspace:FindFirstChild("Torso", true) and Workspace:FindFirstChild("Torso", true).Parent == Workspace:FindFirstChild("Articulating") then --code end
The FindFirstChild method returns false if it's not able to find the child, while the brackets will throw an error if it's not able to find the child.
local = game.Workspace:FindFIrstChild("Part")
For the top code you are still finding Part.
local b = game.Workspace["Part"]
For the top code you are still finding Part.