Studio/ Scripting Questions

Hello all,

I’ve been learning to script/ create things in Roblox Studio, but some aspects have been unclear to me. I would be grateful to any who would answer these questions for me!

WaitForChild vs FindFirstChild vs Dot

when finding/ referencing things in Roblox studio, I’ve noticed several ways to do it. Take these seperate scripts for example.

local part = game.Workspace:WaitForChild(‘Part1’)
part.BrickColor = BrickColor.new(1, 0, 0)

local part = game.Workspace:FindFirstChild(‘Part1’)
part.BrickColor = BrickColor.new(1, 0, 0)

local part = game.Workspace.Part1
part.BrickColor = BrickColor.new(1, 0, 0)

Though different, these scripts all create the desired effect:
Brickcolor

What is the difference between using FindFirstChild, Wait for Child, and a dot?

Naming Issues

Quite simply, whenever I use studio, at the top left of my screen, I sometimes see the name of the game, sometimes a place number. Why is this?
MineSim
MithPlace

And finally, what is the point of putting parentheses () after an if statement to disclose a condition?

if (datastore:GetAsync(initKey) == nil or debugMode == true) then

instead of

if player then


Thank you in advance :slight_smile:

3 Likes

FindFirstChild should be used if the object might not exist
WaitForChild should be used if the object should exist but may have not loaded yet
Dot should be used for an item you know exists.

Parenthesis are not needed for if statements, some people do it for whatever reason.

3 Likes

They all will serve different functions when you use them with different problems, but yes they can serve the same function when you call something globally. Here’s all of the API documentation on this subject:
WaitForChild
FindFirstChild
Workspace

To add to this, FindFirstChild may return nil if the child does not exist so it can be useful in an if statement. For example, if the child you’re looking for does not exist, the if statement will not run.

1 Like

Ok thank you for all of your help so far! This definitely helps!

Here is a good topic you can read FindFirstChild and WaitForChild: Addressing common bad practices and habits of each