Is there a way to reference an object inside of another one other than FindFirstChild?

Hello there, I was reviewing a script when I noticed this line:

local points = player.leaderstats.Points

“Points” is a child of “leaderstats” and “leaderstats” is a child of “player”. Why isn’t this line of code written like this

local pointsparent = player:FindFirstChild(leaderstats)
local points = pointsparent:FindFirstChild(Points)

and why does it work?

1 Like

I’m assuming some-where else in the code they make leaderstats and points; which means it’s defined, and the person who wrote the code knows it’s defined already. The only time you’d use something like

player.leaderstats.Points

is when you can guarantee it’s existence.
Also would like to point out, when using FindFirstChild() you need " " around the name at question.

3 Likes