Hey developers! I am working on something, and was wondering if there is a way to Calculate the groups of classnames a Instance may be apart of, using a script.
Let me explain with an example. I have a part, and the Part classname is Part, as expected and by default. However, the part is also in the grouped classname BasePart, and as well as an Instance.
This is the same with others, like IntValue with BaseValue, And Textlabel with GuiObject AND GuiLabel AND GuiBase
And so my question, is how can I get all the groups of Classnames a Instance may be in, with only having the information provided about the Instance.
Hopefully that makes sense, and I appreciate any help on this issue!
The title is a lil confusing but i get what you mean
I don’t think there’s a way to do this (AFAIK) the only thing i can think of is making a table that haves these types of values
local classNames = {
Frame = "GuiObject",
Part = "BasePart"
}
or something like this then check if the Instance is actually one of these
local instance = Instance.new("Part")
print(classNames[instance.ClassName]) -- BasePart
obviously there are other ways of doing something like this (this is a silly way), but roblox (AFAIK again) doesn’t have any method/service that does this
Well so in studio, Instances have their direct classname (So when you do Instance.Classname , If its a Textlabel, it will be “TextLabel”.)
Now however, some Instances are in a bigger “group”. This is seen with Methods like :IsA, where you can check if an Instance is a specific classname.
So When I do print(TextLabel:IsA("GuiObject")), It prints true, as expected. What I want to know is this:
I have an Instance. What are all the “Classnames” that it will print true with :IsA(NAME_HERE).
I mean this is certainly an option. My only fear is that roblox is everchanging, adding new classnames / Instance Types, like most recently with their Audio API . It is something I have considered but my main worry is maintaining it for the future usage.
It’s a bit complicated to explain the reason; but I will try. I have a list of Instances and I am trying to filter out and group Instances in that list together by the different class names
With user input, the user selects a classname type, and a change is provided to those Instances. The problem I am having is not the “Change to those Instances” but it’s getting the Instances classnames FOR the user to select, and wanting to include these “Secondary grouped classnames” as well
Aight, heres the most Optimal method I COULD THINK OF, it’s not the most optimal method for sure. After looking up stuff and using 10% of my brain, I figured out that you could use an API to get all ClassNames on roblox (or an array), from there, just use an array and loop through the parts that are supposed to be changed, and check if the class exists + if the part is part of that class
To keep it simple, and allow easy and adjustable changes to the list of Filtered Instances. Like, for example to allow you to Change All BaseValue in the Instance list, Instead of going one by one, with IntValue, BoolValue, NumberValue, StringValue etc… The main reason is to allow a broad selection, and less of a restrictive one. Yes, technically I don’t NEED it, but I would really like; if at all possible, to add one, even if I have to make a mannual list of all classnames.
local ClassChange = {}
local HttpService = game:GetService("HttpService")
local Data = HttpService:JSONDecode(HttpService:GetAsync(`https://s3.amazonaws.com/setup.roblox.com/{HttpService:GetAsync("https://s3.amazonaws.com/setup.roblox.com/versionQTStudio")}-API-Dump.json`))
ClassChange.Classes = {}
for _,v in pairs(Data.Classes) do
table.insert(ClassChange.Classes,(#ClassChange.Classes + 1),v.Name)
end
function ClassChange.getInstanceClasses(...)
if type(...) == table then
for _,ins in ... do
if ins.ClassName then
local AllClassesPartBelongsTo = {}
for _,classname in ClassChange.Classes do
if ins:IsA(classname) then
table.insert(AllClassesPartBelongsTo, classname)
end
end
print(AllClassesPartBelongsTo)
return AllClassesPartBelongsTo
else
warn("Failed to find classname.")
end
end
else
for _,ins in {...} do
if ins.ClassName then
local AllClassesPartBelongsTo = {}
for _,classname in ClassChange.Classes do
if ins:IsA(classname) then
table.insert(AllClassesPartBelongsTo, classname)
end
end
print(AllClassesPartBelongsTo)
return AllClassesPartBelongsTo
else
warn("Failed to find classname.")
end
end
end
end
return ClassChange
This is modulescript form
edit: changed it so you can send over tables but idk if it’s good to use