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

How to get list of object properties?

Asked by 6 years ago

Im making plugin that gets selected object propertie's and pastes them into script, so that you don't have to specify every single property manually in script, it already writes all the objects properties for you and you only change what you want later manually in script.

Problem how could i loop through objects properties and get all it's properties names as string values and just print them out?

I looked through forums and found :GetProperties(), but it doesn't seem to work.

3 answers

Log in to vote
7
Answered by
Validark 1580 Snack Break Moderation Voter
6 years ago
Edited 6 years ago

I recently needed a function to get a table of properties of Objects, so I wrote this function. Here you go :D

local ClassProperties do
    -- ClassProperties is a Dictionary of sorted arrays of Properties of Classes
    -- Pulls from anaminus.github.io
    -- Ignores deprecated and RobloxPluginSecurity Properties
    -- Make sure HttpService is Enabled (Roblox Studio -> Home Tab -> Game Settings -> Security -> Allow HTTP requests = "On")

    ClassProperties = {}
    local HttpService = game:GetService("HttpService")

    local Data = HttpService:JSONDecode(HttpService:GetAsync("https://anaminus.github.io/rbx/json/api/latest.json"))

    for i = 1, #Data do
        local Table = Data[i]
        local Type = Table.type

        if Type == "Class" then
            local ClassData = {}

            local Superclass = ClassProperties[Table.Superclass]

            if Superclass then
                for j = 1, #Superclass do
                    ClassData[j] = Superclass[j]
                end
            end

            ClassProperties[Table.Name] = ClassData
        elseif Type == "Property" then
            if not next(Table.tags) then
                local Class = ClassProperties[Table.Class]
                local Property = Table.Name
                local Inserted

                for j = 1, #Class do
                    if Property < Class[j] then -- Determine whether `Property` precedes `Class[j]` alphabetically
                        Inserted = true
                        table.insert(Class, j, Property)
                        break
                    end
                end

                if not Inserted then
                    table.insert(Class, Property)
                end
            end
        elseif Type == "Function" then
        elseif Type == "YieldFunction" then
        elseif Type == "Event" then
        elseif Type == "Callback" then
        elseif Type == "Enum" then
        elseif Type == "EnumItem" then
        end
    end
end

table.foreach(ClassProperties["Part"], print)
Ad
Log in to vote
0
Answered by 6 years ago

There is a model for this. Just follow the instructions in the description.

https://www.roblox.com/library/59938771/GetProperties-function

Log in to vote
-2
Answered by
OfcPedroo 396 Moderation Voter
6 years ago

:GetProperties doesn't work...

There's a way, though, to actually get them; Tho it takes lots of time ;I

This is a working, print example (in a regular script):

game.Players.PlayerAdded:connect(function(player)
--Get Part's properties...
    local Part = game.Workspace.Part
    local BrickColor = Part.BrickColor
    local Color = Part.Color
    local Material = Part.Material
    local Reflectance = Part.Reflectance
    local Transparency = Part.Transparency
    local ClassName = Part.ClassName
    local Name = Part.Name
    local Orientation = Part.Orientation
    local Parent = Part.Parent
    local Position = Part.Position
    local RotVelocity = Part.RotVelocity
    local Velocity = Part.Velocity
    local Anchored = Part.Anchored
    local Archivable = Part.Archivable
    local CanCollide = Part.CanCollide
    local CollisionGroupId = Part.CollisionGroupId
    local Locked = Part.Locked
    local CustomPhysicalProperties = Part.CustomPhysicalProperties
    local Shape = Part.Shape
    local Size = Part.Size

--Print whatever you want (as an example)
    print(Size)
    print(tonumber(Position) + tonumber(Position))
    print(Archivable)
end)

Yes, there's at least by now no automated solution...

If this takes out your doubts, then mark as the solution please.

As always, good scripting.

2
thanks bro iuclds 720 — 3y

Answer this question