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

How can I add a dictionary to an array using code?

I want to get the name of a part and its position, and then add that to an array as a dictionary using code. Not sure how to do this, I can only get 1 key value to be added to the array.

CODE

local partsInGame = {}
local workPlace = game.Workspace:GetChildren()

for i, v in pairs(workPlace) do
	
	if v.Name == "Part" then 
		part = v
		partPos = part.Position		
		newTable = {
			part = partPos
		}	
	end

end

print(newTable)

OUTPUT

{

 ["part"] = 72.8760376, 0.5, -56.6282959

}

  • Server - Script:30

there are 4 parts each named "Part" which needed to be added to the dictionary

DESIRED OUTPUT

{

 ["part"] = "position of part"

 ["part"] = "position of part"

 ["part"] = "position of part"

 ["part"] = "position of part"

}

  • Server - Script:30

1 answer

hey you! have you ever heard of enes? if you are in trouble, better call enes!

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