So this is a script from SpooksHD's video of a map voting system and I have rewritten the script several times with help of the video but the error seems to not fix. The error it gives me is: ServerScriptService.Server:103: attempt to concatenate local 'mName' (a nil value) And if you want to check if I have written everything correct here is the link to spooksHD's video: [https://www.youtube.com/watch?v=1eUCfvC7F1A]. Please do try to find a solution quickly because I have nothing to do but work on my game and I can't go on without a fix for this. Here is the part of the script I think the problem is in:
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
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 settings = { mapVoteTime=15; mapVoteDelay=3; playersRequired=1; } --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 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 = "Winner!" stats.Status.Value = mapVotes[1].mapName.." was chosen!" else b.sGui.Title.Text = "Lost Vote!" end end wait(settings.mapVoteDelay) end end