Finding and editing object properties via string name

I have this folder containing values like so:
Capture

and would like to loop through these values, find the property in lighting from the name of the value, and then set the property to the value inside.

The problem is, I keep getting this error, as if it was looking for a child object of Lighting rather than a property.

Capture

i am using this code block to accomplish this:

    for _, i in pairs(Map.GameSettings:GetChildren()) do
		if game:FindFirstChild(i.Name) then
			local Service = game:GetService(i.Name)
			
			for _, j in pairs(i:GetChildren()) do
				Service[j.Name] = j.Value
			end
		end
	end

Afaik, technology is a readonly variable.
Pcalls might help, I’ll just find some usable code

2 Likes

The error occured with the LegacyOutlines variable as well. (the previous time it read the LegacyOutlines variable first, i tried removing it and then got this error with Technology)

You can’t write to or read the Technology property during runtime. The same for LegacyOutlines.

image

https://developer.roblox.com/en-us/api-reference/property/Lighting/Technology/index.html
https://developer.roblox.com/en-us/api-reference/property/Lighting/LegacyOutlines/index.html

3 Likes

Adding onto what previous users said, please make sure you research! If you go to Lighting.Technology on the Developer Hub, you can see that it states in a large red box at the top of the page that you cannot change this property from a script.
image

https://developer.roblox.com/en-us/api-reference/property/Lighting/Technology/index.html

edit: posted this pretty much at the same exact time as @EpicMetatableMoment, sorry for basically repeating what they said!

3 Likes

Try this;
for _, i in pairs(Map.GameSettings:GetChildren()) do
if game:FindFirstChild(i.Name) then
local Service = game:GetService(i.Name)
function WriteVariable(Name, Value)
Service[Name] = Value
end

		for _, j in pairs(i:GetChildren()) do
			if pcall(WriteVariable(j.Name, j.Value)) do
				--We have succeeded.
			else
				--"Ah we failed!"
				print("Can't write or read", j.Name)
			end
		end
	end
end

That’s not how you pcall a function. That will call WriteVariable and pcall what it returns, since you call it directly instead of passing the function itself to pcall. It’s also if condition then, not if condition do. Here’s what this line should look like:
if pcall(WriteVariable, j.Name, j.Value) then

3 Likes

Sorry, was in the middle of a call on not very much sleep. Though I didn’t know you could call PCalls like that!

1 Like