Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this vote for map script give me an string expected error? [Closed]

Asked by 7 years ago
Edited 7 years ago

I am making a vote for map gui but suddendly it gave me an error i do not know how to fix or where it is cause the error is in the gamescript but it errors on a RemoteEvent line so it's in another script but i do not know where here are the scripts

Game Script

local allmaps = {1,2,3}

-- Main game code
math.randomseed(tick())
local ss = game:GetService("ServerStorage")
local rs = game:GetService("ReplicatedStorage")
local stats = workspace.GameStats
local inPlayPlayers = {}

function Intermission()
    stats.InProgress.Value = true
    if workspace:FindFirstChild("Map") then
        workspace.Map:Destroy()
    end
    stats.GameStatus.Value = "Intermission"
    for i = 5,0,-1 do
        wait(1)
        stats.SecondaryMessage.Value = i
    end


    local map = game.ServerScriptService.ChooseMap.Choose:Invoke(allmaps)
    game.ReplicatedStorage.RoundEvent.MapChosen:FireAllClients(map)

    workspace.GameStats.GameStatus.Value = "Loading Map"

    game.ServerStorage.Maps[map]:Clone().Parent = workspace

end

function getReadyPlayers()
    local players = {}
    for _,v in pairs(game.Players:GetPlayers()) do
        --if v.Data.Playing.Value == true then
            table.insert(players,v)
        --end
    end
    return players
end

while true do
    if workspace.GameStats.InProgress.Value == false then
        if #getReadyPlayers() < 1 then
            stats.GameStatus.Value = "Waiting for players"
        else
            Intermission()
        end
    end
    wait(1)
end

ChooseMap Script

local map1Votes = nil
local map2Votes = nil
local map3Votes = nil

local info = require(game.ReplicatedStorage.MapInformation)

function script.Choose.OnInvoke(tabsOfMaps)

    map1Votes = 0
    map2Votes = 0
    map3Votes = 0

    local choose3 = tabsOfMaps

    int1 = math.random(1,#choose3)
    map1 = choose3[int1]
    table.remove(choose3,int1)  

    int2 = math.random(1,#choose3)
    map2 = choose3[int2]
    table.remove(choose3,int2)

    int3 = math.random(1,#choose3)
    map3 = choose3[int3]
    table.remove(choose3,int3)  

    game.ReplicatedStorage.ServerRequest.ShowMapOptions:FireAllClients(map1,map2,map3)

    local countdown = 100
    workspace.GameStats.GameStatus.Value = "Map Voting"
    repeat
        wait(.1)        
        countdown = countdown - 1
        workspace.GameStats.SecondaryMessage.Value = "Map Voting: "..math.ceil(countdown/10)
        game.ReplicatedStorage.ServerRequest.ShowMapScores:FireAllClients(map1Votes,map2Votes,map3Votes)
    until countdown == 0

    if map1Votes > map2Votes and map1Votes > map3Votes then
        winner = map1
    elseif map2Votes > map1Votes and map2Votes > map3Votes then
        winner = map2
    elseif map3Votes > map1Votes and map3Votes > map2Votes then
        winner = map3
    elseif map1Votes == map2Votes then
        winner = map1
    elseif map1Votes == map3Votes then
        winner = map3
    elseif map2Votes == map3Votes then
        winner = map2
    end

    local mapInfoWinner = info.GetDetails(winner)

    if winner == map1 then
        loser1 = map2
        loser2 = map3
    elseif winner == map2 then
        loser1 = map1
        loser2 = map3
    else
        loser1 = map1
        loser2 = map2
    end 

    local mapInfoL1 = info.GetDetails(loser1)
    local mapInfoL2 = info.GetDetails(loser2)

end

game.ReplicatedStorage.ClientRequest.VoteForMap.OnServerEvent:connect(function(player,bool,mapChoise)
    if mapChoise == 1 then
        if bool then
            map1Votes = map1Votes + 1
        else
            map1Votes = map1Votes - 1
        end
    elseif mapChoise == 2 then
        if bool then
            map2Votes = map2Votes + 1
        else
            map2Votes = map2Votes - 1
        end
    elseif mapChoise == 3 then
        if bool then
            map3Votes = map3Votes + 1
        else
            map3Votes = map3Votes - 1
        end 
    end
end)

errors:

06:57:16.440 - ServerScriptService.GameScript:27: bad argument #2 to '?' (string expected, got nil)
06:57:16.443 - Stack Begin
06:57:16.448 - Script 'ServerScriptService.GameScript', Line 27 - global Intermission
06:57:16.449 - Script 'ServerScriptService.GameScript', Line 46
06:57:16.451 - Stack End
0
Well if you mean the choosemap script, on the first 3 lines you can have nil on a varible ObStactionD3stroy3r 14 — 7y

Answer this question