Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make it print child number 3's name?

Asked by 4 years ago

print(game.Workspace:GetChildren(3).Name) the output i get from this is a table but i want the name, how can i make that happen?

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Since GetChildren returns an array/table you can just do this.

print(game.Workspace:GetChildren()[3].Name)
Ad
Log in to vote
0
Answered by
Lucke0051 165
4 years ago
Edited 4 years ago

You could do: (I don't know why you would do this but ok)

local t = workspace:GetChildren()

local c = 0
for i,v in pairs(t) do
    if c == 3 then
        print(v.Name)
        c = c + 1
    else
        if c < 3 then 
            c = c + 1
        end
    end
end

If you want to find the child with name number 3 do:

if workspace:FindFirstChild("3") then
    print(workspace:FindFirstChild("3").Name)
end

If I didn't understand what you meant please leave a comment.

0
what im trying to do is to print the 3rd child's name and this sadly does not do that, it prints the first 3 children instead Gameplayer365247v2 1055 — 4y
0
I edited, try now Lucke0051 165 — 4y
Log in to vote
0
Answered by 4 years ago

Just a simple way to do it

local ThirdChild = game.Workspace:GetChildren()[3] --Gets the third value from the Array
0
I didnt see Vinceberget Answer ;) and i forgot .Name Luka_Gaming07 534 — 4y

Answer this question