I'm still new with tables and for loops, I made this to try get the distance of every model in game.Workspace.NPCs but the table doesn't work right this is what it prints: Distance is 9.7385768890381 Distance is 58.984462738037 Distance is 67.759483337402 table: 1E10DC80 It prints the distances right but the table part just makes it print random letters and numbers each time, how do I fix this?
while wait(6) do local distances = {} for number,char in pairs (game.Workspace.NPCs:GetChildren()) do local distance = (char.Head.Position - script.Parent.Head.Position).magnitude distances[number] = distance print("Distance is "..distance) end print(distances) end
The 1E10DC80 is actually to do with the table object. If you want to print the contents of the table then you will have to iterate over the table and print each value as follows:
for index, value in ipairs(distances) do print("Distance is "..value) end
MD