How do I get the newest child that has been added to a folder

I would like to print the newest child that has been added to a folder, but I don’t know how to do it

child added event, this is your solution

As Boustifail said, use Instance.ChildAdded to do it. You can have the script store the instance in a value or by other means.

Instance.ChildAdded:Connect() is probably a better way to put it

https://developer.roblox.com/en-us/api-reference/event/Instance/ChildAdded

1 Like

Well I would like to know what the name of the object that is added

Look at the documentation. ChildAdded’s first parameter is the object which was added.

1 Like

Here is the example from the API:

workspace.ChildAdded:Connect(function(child)
	-- need to use WaitForChild as descendants may not have replicated yet
	local head = child:WaitForChild("Head")
end)
1 Like

Note that this only matters if you do this on the client side.

Can’t you just do that on server side? I mean, it isn’t a function client only right?

– need to use WaitForChild as descendants may not have replicated yet

This only matters if it’s ran by the client, not the server.

Can’t you just do that on server side? I mean, it isn’t a function client only right?

This function can be used on both the server and client.

1 Like

I mean, i just did copy paste the example from the API without checking it. But yes, you might need a line of code to wait for it.

1 Like

Waiting (yielding) is only if the instance hasn’t been replicated to the client yet.
You do not need to wait if this function is handled on the server side.

1 Like