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

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

Asked by 2 years ago

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

Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

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

Ad

Answer this question