While naturedat's response is perfectly sufficient in terms of correcting your errors, it doesn't detail exactly what and why what you did was wrong, so I thought I'd weigh in and provide a more thorough explanation. And provide a lot of conventional practices as well.
2 | local timer = game.ReplicatedStorage:WaitForChild( "Information" ):WaitForChild( "Time" ) |
3 | local maps = game.ReplicatedStorage:WaitForChild( "Maps" ) |
First off, you're defining the variables at the beginning of each loop, which is fine, but since they'll never change, it's probably better to just put them before the while loop.
So, it should look like this:
01 | local timer = game.ReplicatedStorage:WaitForChild( "Information" ):WaitForChild( "Time" ) |
02 | local maps = game.ReplicatedStorage:WaitForChild( "Maps" ) |
06 | local chosen 1 = maps [ math.random( 1 ,#maps:GetChildren()) ] |
07 | chosen 1. Parent = workspace.Maps |
09 | local chosen 2 = maps [ math.random( 1 ,#maps:GetChildren()) ] |
10 | chosen 2. Parent = workspace.Maps |
12 | local chosen 3 = maps [ math.random( 1 ,#maps:GetChildren()) ] |
13 | chosen 3. Parent = workspace.Maps |
14 | chosen 1 :SetPrimaryPartCFrame(game.ReplicatedStorage.Positions:WaitForChild( "1" ).Value) |
15 | chosen 2 :SetPrimaryPartCFrame(game.ReplicatedStorage.Positions:WaitForChild( "2" ).Value) |
16 | chosen 3 :SetPrimaryPartCFrame(game.ReplicatedStorage.Positions:WaitForChild( "3" ).Value) |
17 | for i = timer.Value, 0 ,- 1 do |
18 | timer.Value = timer.Value - 1 |
20 | for i,v in pairs (game.Workspace.Maps:GetChildren()) do |
Second, you're attempting to index an instance as though it is a table. You need to call the GetChildren function on the instance to be able to index it, because that function returns a table, containing all of the objects inside of the instance you called GetChildren on. Since you didn't do that when indexing the maps variable, you receive an error, because you were trying to index an instance, and not a table.
I notice that later on in the script you use the maps variable in the context of putting the maps inside of two different instances that go by the name "Maps", one in Workspace and one in ReplicatedStorage. So I think you'll need to set up three variables, one referring to the Maps instance inside of ReplicatedStorage, another referring to the Maps instance inside of Workspace, and one more referring to the table returned by calling GetChildren on the Maps instance inside of ReplicatedStorage. As a matter of fact, you might as well add a variable for the "Positions" instance inside of ReplicatedStorage as well, since you use it multiple times. And for ReplicatedStorage too.
I'm creating variables for each of these things because it can get a little unwieldy to type "workspace.Maps" or "game.ReplicatedStorage.Positions" repeatedly. It just makes things a lot easier and helps to clean up your code a bit.
01 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local timer = replicatedStorage:WaitForChild( "Information" ):WaitForChild( "Time" ) |
04 | local mapsWS = workspace:WaitForChild( "Maps" ) |
05 | local mapsRS = replicatedStorage:WaitForChild( "Maps" ) |
06 | local mapsTable = mapsInstance:GetChildren() |
07 | local positions = replicatedStorage:WaitForChild( "Positions" ) |
11 | local chosen 1 = mapsTable [ math.random( 1 ,#mapsTable) ] |
12 | chosen 1. Parent = mapsWS |
14 | local chosen 2 = mapsTable [ math.random( 1 ,#mapsTable) ] |
15 | chosen 2. Parent = mapsWS |
17 | local chosen 3 = mapsTable [ math.random( 1 ,#mapsTable) ] |
18 | chosen 3. Parent = mapsWS |
19 | chosen 1 :SetPrimaryPartCFrame(positions:WaitForChild( "1" ).Value) |
20 | chosen 2 :SetPrimaryPartCFrame(positions:WaitForChild( "2" ).Value) |
21 | chosen 3 :SetPrimaryPartCFrame(positions:WaitForChild( "3" ).Value) |
22 | for i = timer.Value, 0 ,- 1 do |
23 | timer.Value = timer.Value - 1 |
25 | for i,v in pairs (mapsWS:GetChildren()) do |
I replaced a lot of the repeated uses of code with the variables defined just before the while loop and it's already looking a lot cleaner. I know this is way over the top and much more than you asked, but I tend to value intricate corrections over simpler ones. Or maybe I just have OCD. Anyways, there are still some things to note.
When calling the math.random function, you can just pass in one value and it'll automatically return a random value between 1 and the value you passed in, so putting this:
1 | math.random( 1 ,#mapsTable) |
is redundant.
Put this instead:
The result is exactly the same.
This bit of code right here isn't really problematic, but as opposed to this:
1 | for i = timer.Value, 0 ,- 1 do |
2 | timer.Value = timer.Value - 1 |
You can just do this:
1 | for i = timer.Value, 0 ,- 1 do |
You also need to add a wait function inside of that loop so that the loop doesn't fully execute in an instant:
1 | for i = timer.Value, 0 ,- 1 do |
So, the final code should look like this:
01 | local replicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local timer = replicatedStorage:WaitForChild( "Information" ):WaitForChild( "Time" ) |
04 | local mapsWS = workspace:WaitForChild( "Maps" ) |
05 | local mapsRS = replicatedStorage:WaitForChild( "Maps" ) |
06 | local mapsTable = mapsInstance:GetChildren() |
07 | local positions = replicatedStorage:WaitForChild( "Positions" ) |
11 | local chosen 1 = mapsTable [ math.random(#mapsTable) ] |
12 | chosen 1. Parent = mapsWS |
13 | local chosen 2 = mapsTable [ math.random(#mapsTable) ] |
14 | chosen 2. Parent = mapsWS |
15 | local chosen 3 = mapsTable [ math.random(#mapsTable) ] |
16 | chosen 3. Parent = mapsWS |
17 | chosen 1 :SetPrimaryPartCFrame(positions:WaitForChild( "1" ).Value) |
18 | chosen 2 :SetPrimaryPartCFrame(positions:WaitForChild( "2" ).Value) |
19 | chosen 3 :SetPrimaryPartCFrame(positions:WaitForChild( "3" ).Value) |
20 | for i = timer.Value, 0 , - 1 do |
24 | for i,v in pairs (mapsWS:GetChildren()) do |
I know I went way overboard with this answer, but I just like to give very informative responses whenever I answer questions on this website, lol. If I don't, it just makes me feel like I'm farming reputation points.