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

How to change a property by only getting the property name?

Asked by
ew_001 58
4 years ago

Ok so I did'nt really know what to call the title, but I was having a function that could create a part and you pass trough some properties but instead having a varible in the funcation for every poropertie. I wanted to make a table with all properties in it. I tried this.

01function AddProperty(PropertyTable,Obj)
02    Obj[PropertyTable.Name] = PropertyTable.Value
03end
04 
05function CreateObject(Type,Properties)
06    local Obj = Instance.new(Type,game:GetService("Workspace"))
07 
08    for i = 1,#Properties do
09        local PropertyTable = Properties[i]
10        AddProperty(PropertyTable)
11    end
12end
13 
14CreateObject("Part",{{Name = "Size", Value = Vector3.new(10,10,10)}})

But when I type "Obj[PropertyTable.Name]" it tries to find a object inside the object with that name. Not changing the propertie. Is there any way to do this without using loadstring becuase I cant seem to be able to use it anymore.

0
I imagine it's checking for an object in the object because that's how you've written it Obj[PropertyTable.Name] looks like Obj.PropertyTable.Name, which doesn't exist. I don't think you can do this without assigning a local variable so it becomes a single dot operation. radiant_Light203 1166 — 4y
0
i got this answer from the discord server too but thanks ew_001 58 — 4y

Answer this question