Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add values into a table?

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

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.