Code support - How do i use parents in roblox scripts?

Hello, I would like to know if someone could share example script to learn how to use parents and implement it in learning scripts that I will do now.

I have been learning to program in roblox for a month now and I have learned a lot but I have much more to learn and this is on my list, I would greatly appreciate it if you could share your knowledge with me, greetings.

Parents is what a child (Instance) is underneath and belongs to

-- code example:

local part = Instance.new("Part")
part.Parent = workspace -- the part will now appear under workspace because that's what it's parent is

local part2 = Instance.new("Part")
part.Parent = part -- the part will appear in workspace (because of descendants) but it's parent will be "part"

When using Instance.new or Instance:Clone, the object in question is parented to nil by default. nil means something has no value.

Instance.new can take a parent argument second (Instance.new("Part", workspace)) but if you care about performance then this isn’t recommended because Roblox has to constantly refresh the object after every time it’s used.

The developer hub page explains more of it:

1 Like

Please try searching before posting, most of the questions you have sent have been answered before:
image
https://developer.roblox.com/en-us/api-reference/property/Instance/Parent

3 Likes

Previously I had already read it from the docs but in this post I wanted those who can share their knowledge with the aim of learning much more

Thanks a lot! I will use it to learn today :smiley: