You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I am ‘Attempting’ to create a tower of hell style game but 2D.
What is the issue? Include screenshots / videos if possible!
The issue is I’ve looked all over, and I can’t seem to randomly pick it from my folder. (I made sure all my paths are correct, so that’s not the problem.)
local RGM = game.ServerStorage.Stages.s1st
local randomMap = RGM[math.random(#1,RGM:GetChildren())]
randomMap:Clone().Parent = workspace.CurrentStages.c1st
The error down below seems to lead to here when I click it.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to look in scripting helpers, the devforum, and the developer hub but can’t seem to find any.
I’m going to split that up because it’s doing a lot of stuff at once, to help you easier understand.
First you want to reference your folder:
local ServerStorage = game:GetService("ServerStorage")
local mapFolder = ServerStorage.Stages.s1st
Once you have the folder, you want to get a table of all the maps inside the folder. Then, we can pick randomly since they will all be in the table. To get a table, we use GetChildren(), as that returns a table of the children.
local maps = mapFolder:GetChildren()
So we have the table. Now we need to get a random number we will use to index the table. We want the random number to be between 1 and the number of maps inside of the folder. So we will do:
local randomIndex = math.random(1, #maps)
This will give you the random number. Now with the number, you can index and find a map.
local randomMap = maps[randomIndex]
You now have a reference to the randomMap, and you can do whatever with it. In your case:
local randomClone = randomMap:Clone()
randomClone.Parent = workspace.CurrentStages.c1st
And putting it all together:
local ServerStorage = game:GetService("ServerStorage")
local mapFolder = ServerStorage.Stages.s1st
local maps = mapFolder:GetChildren()
local randomIndex = math.random(1, #maps)
local randomMap = maps[randomIndex]
local randomClone = randomMap:Clone()
randomClone.Parent = workspace.CurrentStages.c1st
Lol, this is neat! It’s definitely bad programming practice though. It’s important to take readability in account and should probably not be sacrificed for brevity, unless the brevity is also easily understandable.