I am making a map voting script for my GUI and when I go to run the script I get this output:
01:22:09.428 - ServerScriptService.Server:104: attempt to concatenate nil with string
The error is happening on line 104:
--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 = game.StarterGui.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 player already voted on a map, if so then change map 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 map votes 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").."need to play!" else --assign maps mapVotes={} for a,b in pairs(Game.Special.VotingGUIs.ScreenGUI: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.VotingGUIs.ScreenGUI: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.VotingGUIs.ScreenGUI: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" wait(settings.mapVoteDelay) end end end end
if anyone knows the problem and how to fix it please tell me. I've tried everything I knew for the past 3 hours and I can't seem to get it to work.
And b = VotingGUI and the ScreenGUI holds all of those down to the text so it looks like this:
VotingGUI>sGUI>Title (which is a TextLabel renamed as "Title")
EDIT: added the local script that goes along with the server script:
--Player-- local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:wait() local gui = player:WaitForChild("PlayerGui") local ui= gui:WaitForChild("ui") --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 --Game Variables-- local Game = game.StarterGui.Game local stats = Game.Stats --Static Variables-- local vars = { currentVote=nil; services={}; } --Primary Events-- event.OnClientEvent:connect(function(variables) if variables.reason == "startVoting" then table.insert(vars.services, game:GetService("RunService").RenderStepped:connect(function() local ray = Ray.new(char.PrimaryPart.CFrame.p, Vector3.new(0.-1000.0)) local object = workspace:findPartOnRay(ray, char, false, false) if object and object.Name:match("VotingButton") then local votingGUINum = tonumber(object.Name:match("%d+")) if vars.currentVote==nil then vars.currentVote = votingGUINum event:FireServer({reason="voteOnMap"; itemNum=votingGUINum;}) elseif vars.currentVote~=votingGUINum then vars.currentVote = votingGUINum event:FireServer({reason="voteOnMap"; itemNum=votingGUINum;}) end elseif vars.currentVote~=nil then vars.currentVote=nil event:FireServer({reason="removeFromVote"}) end end)) elseif variables.reason == "endVoting" then for a,b in pairs(vars.services) do b:disconnect() end vars.services= {} end end) --Initiate Title Updater game:GetService("RunService").RenderStepped:connect(function() ui:WaitForChild("Title").Text = game.StarterGui.Game.Stats.Status.Value end)
I think you should put an if on line 104 before changing the text so it is not nil
if mName and playersVoting then b.sGui.Title.Text = mName.." - "..playersVoting.." "..((playersVoting==1 and "Voter")or "Voters") end