Script Getting the Children Inside of the Chosen Map

Hello, how could I just get the maps from the folder instead of getting the stuff inside of the map folder? I’ve tried removing the get children although the output shows table expected got instance.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MapsList = ReplicatedStorage:FindFirstChild("Maps"):GetChildren()
local ChosenMaps = MapsList[math.random(2, #MapsList)]:GetChildren()

local Voting = script.Parent
local Maps = Voting:FindFirstChild("Maps")
local Template = script:FindFirstChild("Template")

function CreateFrame(Map, Image)
    local Frame = Template:Clone()
    
    Frame.Name = Map
    Frame.Title.Text = Map
    Frame.Image = Image
    
    Frame.Parent = Maps
    return Frame
end

function AddMaps(Data)
    for i, v in ipairs(Data) do
        local Frame = CreateFrame(v.Name, v.Image.Value)
    end
end

AddMaps(ChosenMaps)
local ChosenMaps = MapsList[math.random(2, #MapsList)]:GetChildren()

Instead of this, replace it with this :

local ChosenMaps = MapsList[math.random(1, #MapsList:GetChildren())]

Since you want to choose a random map out of #YourMaps, you want to get a random number between 1[normal, classic] to the number of maps you have inside of that folder

You need GetChildren(), don’t remove it.

or above

With this in game it says in the output attempt to call a nil value.

Oh, my bad!
Replace it with :
local MapsList = ReplicatedStorage:WaitForChild(“Maps”)

local ChosenMaps = MapsList[math.random(1, #MapsList:GetChildren())]

EDIT: TRY THE UPDATED ONE

With this the output displays “invalid argument #1 to ‘ipairs’ (table expected, got Instance)”

Okay so I tried the updated one although it says 3 is not a valid member of folder in replicated storage.

Replace your first 3 lines with that :

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MapsList = ReplicatedStorage:FindFirstChild(“Maps”)
local ChosenMaps = MapsList[math.random(1, #MapsList:GetChildren())]

The error in the script shows on line 3.

Oh, I now see this.

Do this :

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsList = ReplicatedStorage:FindFirstChild("Maps")
local ChosenMap = MapsList:GetChildren()[math.random(1, #MapsList:GetChildren())]

print(ChosenMap.Name)

What happend here
After we got the maps folder, we actually need to get the map by getting a random map out of all the existent maps.

Okay so with this it printed one of the maps in the folder although it says its an invalid argument to ipairs as it expected a table, but it got nil.

Alright, so you gave the function AddMaps a parameter - Data,
and you then called it with the argument ChosenMap.

The problem is here, because you need to put a table inside the ipairs ()
try put there Data:GetChildren()

Alright so with this we’re back at square one since it’s now looking at the children inside of the map.

Alright, so the system still chooses a map, what does it print to you now?

Alright it prints the map name but then that error shows in the output.

Alright, here it is :


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsList = ReplicatedStorage:FindFirstChild("Maps")
local ChosenMap = MapsList:GetChildren()[math.random(1, #MapsList:GetChildren())]

--print(ChosenMap.Name)





function AddMaps(Data)
	for i, v in ipairs(Data:GetChildren()) do
		--your code
	end
end

AddMaps(MapsList:FindFirstChild(ChosenMap.Name))




local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsList = ReplicatedStorage:FindFirstChild("Maps")
local ChosenMap = MapsList:GetChildren()[math.random(1, #MapsList:GetChildren())]

--print(ChosenMap.Name)

local Voting = script.Parent
local Maps = Voting:FindFirstChild("Maps")
local Template = script:FindFirstChild("Template")



function CreateFrame(Map, Image)
	local Frame = Template:Clone()

	Frame.Name = Map
	Frame.Title.Text = Map
	Frame.Image = Image

	Frame.Parent = Maps
	return Frame
end






function AddMaps(Data)
	for i, v in ipairs(Data:GetChildren()) do
		local Frame = CreateFrame(v.Name, v.Image.Value)
	end
end

AddMaps(MapsList:FindFirstChild(ChosenMap.Name))



Make sure your maps really have something inside of them, otherwise the loop ‘won’t’ find any child to loop through

Okay so there’s a string value named images inside with an image id, but with this new script it’s attempting to find the image inside of the value.

Could you share a screenShot ? [Show the maps folder with their children]