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

Insert Values Into Dictionary?

Asked by 4 years ago
Edited 4 years ago

What I need to be able to do is get the children of an object and create/insert into a dictionary. For example, I want the end dictionary to be like...

Thing1Name = {
[thing1child] = thing1.Value
[thing1child2] = thing2.Value
}

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

This is the general format for adding to a dictionary:

myDictonary[key] = value

if you wanted to add an an item to Thing1Name with the key "Part" and the value game.Workspace.Part, then you'd say:

Thing1Name["Part"] = game.Workspace.Part

I'm guessing you're trying to save a bunch of object values into a dictionary.

Let's say we had a setup like this in the workspace.

to put all those values into a table we'd say:

local myDictionary = {}

for _, child in pairs(game.Workspace.Data:GetChildren())do
    myDictionary[child.Name] = child.Value 
end

0
You alright? royaltoe 5144 — 4y
Ad

Answer this question