How To Use Dictionaries For ModuleScript Functions

I’m curious, how do I use dictionaries as parameters for modulescript functions? Like for example, change a property of a part via data in a dictionary or something like that?

An example of what I’m thinking of:

--[[MODULESCRIPT]]--

function module.CreatePart(parameterTest1)
   local partNew = Instance.new("Part")
   -- INSERT HOW IM SUPPOSED TO USE DICTIONARIES TO CHANGE PART PROPERTY
end

--[[SCRIPT]]--
local dictionaryProperty = {
   ["Anchored"] = true,
   ["CanCollide"] = false,
   ["Name"] = "testPart"
}

module.CreatePart(dictionaryProperty)
1 Like

You can just go through the dictionary in a pairs loop and use the key in each iteration to determine where to put the property.

function module.CreatePart(parameterTest1)
   local partNew = Instance.new("Part")
   
   for PropertyName, Value in pairs(parameterTest1) do
      partNew[PropertyName] = Value
   end
end

--[[SCRIPT]]--
local dictionaryProperty = {
   ["Anchored"] = true,
   ["CanCollide"] = false,
   ["Name"] = "testPart"
}

module.CreatePart(dictionaryProperty)
1 Like

Alright it works, thank you!

[too little characters]