My script is used for a map voting system consisting of 3 pads on the ground which users stand on to vote. However, on line 104 of this script, I am getting this error: 09:49:22.066 - ServerScriptService.Server:108: attempt to concatenate local 'mName' (a nil value).
Here is the full script:
--Assets--
local rep = game.ReplicatedStorage
local assets = rep.Assets
--Maps--
local maps = assets.Maps
--Signals--
local signals = assets.Signals
local event = signals.Event
local fevent= signals.FEvent
--Static Variables--
local mapVotes = {}
--Game Variables--
local Game = workspace.Game
local stats = Game.Stats
local g_maps = Game.Maps
local settings = {
mapVoteTime =15;
mapVoteDelay = 3;
playersRequired = 1;
mapTeleportDelay = 2;
}
--Primary Events--
--[[
ARRAY = mapVotes
MapArray
Id
mapName
players
player = userId
--]]
event.OnServerEvent:Connect(function(player, variables)
if variables.reason == "voteOnMap" then
--First check if a player already voted on a map, if so change vote.
for a,b in pairs (mapVotes) do
for d,c in pairs(b.players) do
if c.player == player.UserId then
table.remove(b.players, d)
break
end
end
end
--Add player to the mapvotes--
for a,b in pairs(mapVotes) do
if b.id == variables.itemNum then
table.insert(b.players, {player = player.UserId})
end
end
elseif variables.reason == "removeFromVote" then
for a,b in pairs (mapVotes) do
for d,c in pairs(b.players) do
if c.player == player.UserId then
table.remove(b.players, d)
break
end
end
end
end
end)
function getMap()
local randomMap = maps:GetChildren()[math.random(1,#maps:GetChildren())]
for a,b in pairs(mapVotes)do
if b.mapName == randomMap.Name then
return getMap()
end
end
end
while wait() do
if #game.Players:GetPlayers() <settings.playersRequired then
local playersNeeded = settings.playersRequired-#game.Players:GetPlayers()
stats.Status.Value = playersNeeded.." "..((playersNeeded==1 and "Player") or "Players").." needed to play."
else
--Assign maps
mapVotes={}
for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
table.insert(mapVotes, {id=tonumber(b.Name:match("%d+")); mapName=getMap(); players = {};})
end
--Fire Clients, start sending in votes--
event:FireAllClients({reason="startVoting"})
--Do main loop--
local start = tick{}
while wait() do
if tick() - start >= settings.mapVoteTime then break end
local secondsLeft = math.floor (settings.mapVoteTime - (tick()-start))
stats.Status.Value = secondsLeft.." "..((secondsLeft==1 and "Second") or "Seconds").." Left to vote"
for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
local playersVoting, mName
for d,c in pairs(mapVotes) do
if c.id == tonumber(b.Name:match("%d+")) then
playersVoting=#c.players
mName = c.mapName
break
end
end
b.sGui.Title.Text = mName.." - "..playersVoting.." "..((playersVoting==1 and "Voter") or "Voters")
end
end
--Get Winner--
table.sort(mapVotes, function(a,b) return #a.players>#b.players end)
for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
if tonumber(b.Name:match("%d+"))== mapVotes[1].id then
b.sGui.Title.Text = "Chosen!"
stats.Status.Value = mapVotes[1].mapName.." was chosen"
b.sGui.Title.BackgroundColor3 = Color3.fromRGB(0,255,0)
else
b.sGui.Title.Text = "Lost Vote!"
end
end
--Load Map
local map = maps[mapVotes[1].mapName]:Clone()
map.Parent = g_maps
wait(settings.mapTeleportDelay)
--Teleport Players
local cachedSpawns = {}
local playersPlaying = {}
for a,b in ipairs(game.Players:GetPlayers()) do
local character = b.Character or b.CharacterAdded:wait()
if character then
local randomSpawn = map.Spawns:GetChildren()[Random.new():NextInteger(1, #map.Spawns:GetChildren())]
if cachedSpawns[randomSpawn] then
repeat randomSpawn = map.Spawns:GetChildren()[Random.new():NextInteger(1, #map.Spawns:GetChildren())] wait() until not cachedSpawns[randomSpawn]
end
cachedSpawns[randomSpawn] = true
character:SetPrimaryPartCFrame(randomSpawn.CFrame * CFrame.new(0,2.25,0))
table.insert(playersPlaying,b.UserId)
end
end
wait(settings.mapVoteDelay)
--Unload Map--
map:Destroy()
--Teleport Players Back--
for a,b in ipairs(playersPlaying) do
local player = game.Players:GetPlayerByUserId(b)
if player then
local character = player.Character or player.CharacterAdded:wait()
if character then
character:SetPrimaryPartCFrame(CFrame.new())
end
end
end
end
end
`~~~~~~~~~~~~~~~~~
`
