Calculate all classnames a Instance may be classified as

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!

2 Likes

Not sure what you mean here exactly, can you reword it?

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).

Does that make any more sense?

1 Like

You should research on the all the classes in the roblox API and make a tree for yourself.

Here’s every single class.

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.

Then it’s not gonna be easy…

But, what are you trying to do with the ClassNames?

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

And what are you trying to do with the list?

You forgot PVInstance lol

Just do what everyone else says. Make a tree. Start from Instance, go through all Bases. Simple. Time consuming but yea.

If Roblox adds new classes it’ll take you two minutes maximum to add them to your tree.

1 Like

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

This is exactly what I’m saying, I’m not familiar with any methods to manually obtain related classes in script.

Why exactly do you want to include “Secondary grouped classnames”?

Edit: I read the post wrongly, my bad.

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

probably dumb im gonna try and make psuedocode

1 Like

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.

2 Likes

got it working
image
when I give you the code keep in mind it isn’t optimal, especially on large scales, it’s the best I can make it

also stole some code from this handsome fellow


so shoutout to him

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

4 Likes

It seems to work, thank you so, so, so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.