So I want to change the property of all these parts by a RemoteEvent (see picture). But how do I do that? Do I just script them one by one or is there a faster way? Something with GetChildren()? (Tag me when a solution is found)
Picture: http://prntscr.com/k8rl2t
Script that I tried:
1 | game.ReplicatedStorage:WaitForChild( "ExteriorLightsEvent" ).OnServerEvent:Connect( function (Player, ExtLight) |
2 | if ExtLight:GetChildren().Transparency = = 0 then |
3 | ExtLight:GetChildren().Transparency = 1 |
4 | else |
5 | ExtLight:GetChildren().Transparency = 0 |
6 | end |
7 | end ) |
Script that works (for one part):
1 | game.ReplicatedStorage:WaitForChild( "ExteriorLightsEvent" ).OnServerEvent:Connect( function (Player, ExtLight) |
2 | if ExtLight.hlight 2. Transparency = = 0 then |
3 | ExtLight.hlight 2. Transparency = 1 |
4 | else |
5 | ExtLight.hlight 2. Transparency = 0 |
6 | end |
7 | end ) |
Thanks in advance.
GetChildren
like that. You're attempting to get every single object from the table, but incorrectly. You can use a for
loop to accomplish this:01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local ExtLightsEvent = ReplicatedStorage:WaitForChild( "ExtLightsEvent" ) |
03 |
04 | ExtLightsEvent.OnServerEvent:Connect( function (player, ExtLight) |
05 | for _, v in pairs (ExtLight:GetChildren()) do |
06 | -- v acts as the element in the table |
07 | if v:IsA( "BasePart" ) and v.Transparency < = 0 then |
08 | -- prone to script error if the object isn't a part. i got you |
09 | v.Transparency = 1 |
10 | end |
11 | end |
12 | end ) |
GetChildren
. Scripting one by one is time consuming, complicated at times, and life could be made easier from one script that handles everything.