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

why is this table.insert script printing out some weird codes?

Asked by 4 years ago
for i,v in pairs(game.Workspace.abc:GetChildren()) do   
    local tab,val = {},v.Name
    table.insert(tab, val)
    print(tab,val)
end

Basically this script is supposed to print "test" since the parts in abc model are t, e, s, t but instead i get this: table: 0x0ba418710f62d17d t table: 0xfb33a005be1626bd e table: 0x6f05649465964e3d s table: 0x1b34c652dafdfa5d t

im a scripting beginner so maybe thats just a feature that i dont know about. any help would be appreciated.

0
Currently, you're printing out the table value. Not the value inside the table. killerbrenden 1537 — 4y
0
ooh k thanks TFlanigan 86 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

You are trying to print the table, not the value in the table. Also another thing i would like to point out is you are trying to do table.insert(table, value) when the second parameter should really be the position where the value is gonna be inserted. So in your case you should do table.insert(tab, 1, value). And to print out the value and not the table use print(tab[1])

0
The position parameter is optional. If only two paramters are passed, the second parameter is assumed to be the value. cowsoncows 951 — 4y
0
Ooh didint know that spicychilly2 145 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I'm not 100% sure what you're trying to do, but I created this script that lists all the objects in Workspace and puts them inside the table.

for _,part in pairs(game.Workspace:GetChildren()) do
    local tab,val = {},part.Name
    table.insert(tab,val)
    print(tab[1])
end

To index the value of a table you have to do this.

print(TABLE_NAME[WHICH VALUE YOU WANT INDEXED])

And that will print the number 1 spot in the table name.

If you need more explanation, let me know. I'm willing to help a fellow scripter out.

Answer this question