Help me with properties

I’ve been programming for a long time, and I still have doubts if I can access a property using a string, this will make my script cleaner.

Example:

local Test = {
	['InstancePart'] = {
		["Transparency"] = 0.5,
		["CFrame"] = CFrame.new(),
	}
}

for i,v in pairs(workspace:GetChildren()) do
	local MyTable = Test[v]
	if MyTable then
		for PropertyName,Value in pairs(MyTable) do
			v:SetProperty(PropertyName,Value) --[[Here where I wanted
			to know something like "SetProperty" the first argument is
			the name of the property and the second argument is the value
			to be set.]]
		end
	end
end

I was just trying something like workspace.Part["Transparency"] = 1 and that seems to work, so I guess I can use tables with that anyway, thanks for your time!

1 Like

You can still Access both Properties and Instances via string, so like you have an item with a Space in it, you can do:

Instance["Item With a Space In It"].Property = value

Instance["Color"] = Color3.new(1,0,0)

However, it can work both ways:

local Test = {
	['InstancePart'] = {
		["Transparency"] = 0.5,
		["CFrame"] = CFrame.new(),
	}
}
Test.InstancePart.Transparency
Test['InstancePart']["Transparency"]

Is there a way I can get all the properties of an instance?

1 Like

I dont think so, but I know you can get all the Attributes with the Usage of Instance:GetAttributes()

If you want, you can look at Documentation on what Properties are inherited from a certain class.

1 Like

okay, thanks for your time! I will read about.

It is possible… but it’s really confusing and apparently requires the use of HttpService()…

Also I find it funny and weird that GetAttributes() exists but GetProperies() doesn’t… not gonna lie Roblox should add it–I think it would be useful in some cases.

I agree with you, imagine making a Table that stores data from properties of several objects with ease.

1 Like

You can literally do that with modules?

yes but it would be much simpler, instead of lines of code to know what object it is and what properties the specific object has, you know? could use just a GetProperies(), it would be better.

2 Likes
workspace.Part['Transparency'] = 1

local propertiesToChange = {
CanCollide = true,
Locked = false,
CustomPhysicalProperties = PhysicalProperties.new(Enum.Material.DiamondPlate),
Anchored = true,
Transparency = .5,
Material = Enum.Material.Glass
}
for key, value in pairs(propertiesToChange) do
part[key]=value
end

I already managed to do this in my script, but thank you very much for your time!

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