Get/Set Instance Properties

As a developer it is currently too hard to get all the properties of an instance at once. This is annoying when you’re trying to save properties of instances you’ll need to define one by one.

This type of requests were made before yet for the sake of not Necro Bumping threads and implanting several optional variables that weren’t mentioned before into the method for it to be handled properly I wanted to request it.

I have thought of a couple of API implementations for in Studio.

:GetProperties(PropertyNames)

This returns a Dictionary of all the properties within the instance with the Name, Value order.
values that are not UTF-8 will get converted into a Dictionary such as Vector3 and Udim
Code Example

local part = workspace.Part

local PartData = part:GetProperties()
--[[ 
add properties you'd like to retrieve within brackets.
for example; part:GetProperties("Anchored", "Enabled"). however this requires the
method to be in runtime. so a better sollution to that would be:
part:GetProperties({"Anchored", "Enabled"}) 

using a table instead of it being in runtime.

keep it empty for it to retrieves all the properties.
]]
print(PartData.Position) -- >> Table: 0x~
print(PartData.CFrame.LookVector) -- >> Table: 0x~
print(PartData.CFrame.LookVector.X) -- >> LookVector.X

local success, err = pcall(function() 
    return Datastore:SetAsync("Key", PartData)
end)

This would allow developers to either send the table over via HTTP or save it as data without using the amount of effort that could easily be used for something else. The solution provided is alike to CFrame’s :GetComponents() yet defined for all the properties.

:SetProperties(PropertyTable)

This is used for easily setting the properties of for example a part. Keep note that if the table contains values that aren’t adjustable in the part, they just get ignored by SetProperties to prevent future complications.

Code Example

local partProps = workspace.Part1:GetProperties()
workspace.Part2:SetProperties(partProps); 
-- Part2 now has the same properties as Part 1.

workspace.Part3:SetProperties({CFrame = partProps.CFrame, Size = partProps.Size})
-- Part3 has it's own properties except for the CFrame and the Size. these are the
-- same as Part1

If this issue is addressed, it would improve my development experience because the mentioned solution will save enormous amounts of time when scripting and makes the script being less filled up than when having to do this manually. The current games start to have to deal with more and more of instance property saving and eventually adding this will be convenient in the present and the future.

6 Likes

This topic was automatically closed after 1 minute. New replies are no longer allowed.