Help with finding selected map

Hi! im trying to make a voting system. But i have an error. Plase help, thanks!

localscript;

local replicatedStorage = game:GetService("ReplicatedStorage")
local voteEvent = replicatedStorage:WaitForChild("Vote")

local maps = replicatedStorage:WaitForChild("Maps"):GetChildren()
local randomMap = maps[math.random(1, #maps)]

local gui = script.Parent
local mainFrame = gui.MainFrame
local mapsFrame = mainFrame.MapsFrame

for i=1 ,#maps do
	local newMap = mapsFrame.Template:Clone()
	local map = maps
	local mapInfo = map:WaitForChild("MapInfo")
	
	newMap.Name = maps.Name
	newMap.MapName.Text = maps.Name
	newMap.Votes.Text = mapInfo.Votes.Value 
	newMap.Visible = true
	
	newMap.Vote.MouseButton1Click:Connect(function()
		if mapInfo then
			voteEvent:FireServer(map)
		else
			warn(map.Name.." does not have map information.")
		end
		
		mapInfo.Votes.Changed:Connect(function()
			newMap.Votes.Text = mapInfo.Votes.Value
		end)
	end)
end

error;

Players.AkexinxYedek.PlayerGui.VoteGui.Main:14: attempt to call a nil value  
1 Like

What line are you getting the error on

1 Like

line 14
(character limittttttttt)

Is this your error line?
If so then there’s a problem with it. You can’t use :WaitForChild() on a table(map being your table because you just made redefined maps). Try changing
local map = maps to local map = maps[i]

2 Likes

The thing is, im trying to get the currentMap

I’ll try that right now.
[char limittttt]

still same error.
(character limit)

local replicatedStorage = game:GetService("ReplicatedStorage")
local voteEvent = replicatedStorage:WaitForChild("Vote")

local maps = replicatedStorage:WaitForChild("Maps"):WaitForChild("MapInfo") 
local randomMap = maps[math.random(1, #maps)]

local gui = script.Parent
local mainFrame = gui.MainFrame
local mapsFrame = mainFrame.MapsFrame

for i=1 ,#maps do
	local newMap = mapsFrame.Template:Clone()
	local map = maps
	local mapInfo = map:WaitForChild("MapInfo")
	
	newMap.Name = maps.Name
	newMap.MapName.Text = maps.Name
	newMap.Votes.Text = mapInfo.Votes.Value 
	newMap.Visible = true
	
	newMap.Vote.MouseButton1Click:Connect(function()
		if mapInfo then
			voteEvent:FireServer(map)
		else
			warn(map.Name.." does not have map information.")
		end
		
		mapInfo.Votes.Changed:Connect(function()
			newMap.Votes.Text = mapInfo.Votes.Value
		end)
	end)
end

Try this

1 Like

Print your map variable and also try printing the maps table since they are both the same

1 Like

the error is fixed, but this time im not getting the map showing up. Its need to be showing up.
image

Parent the newMap variable to the frame

1 Like

Thanks, worked!
(character limit)

2 Likes