I'm trying to put the name of parts in a table, then find those parts in the workspace.
My code:
lights = {"Light1"} i = 1 repeat game.Workspace.lights[i].PointLight.Brightness = game.Workspace.lights[i].PointLight.Brightness - .1 game.Workspace.lights[i].PointLight.Range = game.Workspace.lights[i].PointLight.Range - .1 if i == #lights then i = 1 else i = i + 1 end until game.Workspace.lights[#lights].PointLight.Range == 0
This errors, "lights is not a valid member of Workspace". So how can I find a part using the name of it in a table?
You'd want to use :FindFirstChild()
for this.
Here is a basic use of this.
PartName = "Light" PartObject = game.Workspace:FindFirstChild(PartName) PartObject.Name = "Light 1" PartObject.Color = "Red"
So your code would be:
lights = {"Light1"} i = 1 repeat object = game.Workspace:FindFirstChild(lights[i]) object.PointLight.Brightness = object.PointLight.Brightness - .1 object.PointLight.Range = object.PointLight.Range - .1 if i == #lights then i = 1 else i = i + 1 end until object.PointLight.Range == 0