What does Parent, FindFirstChild and Children means? What effect do They have.
Parent is like where they part is or whats before the part. So if we had a ScreenGui and inserted a frame within that ScreenGui the parent would be ScreenGui.
FindFirstChild is useful is many ways. You use this when you want to find the first child of a part. Ex. workspace:FindFirstChild("Part"). This will find the first child within workspace named part.
GetChildren is used when you want to get all the children of something. Ex. workspace:GetChildren(). This will get all the children within workspace.
Sometimes, such as when you're getting some part from a player, you would use FindFirstChild()
. The reason why is because using just a .
would do it instantly find a child, and not try again. FindFirstChild()
would keep searching until the arguement
inside of the brackets is found.
Take example:
local character = game.Players.LocalPlayer.Character local HumaniodRootPart = character.HumanoidRootPart
If your script was like this, then the output would say something related to:
HumanoidRootPart is not a child of game.Players.LocalPlayer.Character
.
To fix that, you would use the FindFirstChild()
Here's the fixed example:
local character = game.Players.LocalPlayer.Character local HumaniodRootPart = character:WaitForChild("HumanoidRootPart")
Hope you understand mate! Have an amazing day :D