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
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]
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