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

Why does my For Loop turns my table value to zero?

Asked by 4 years ago

I'm having problems with the For loop inside my OnJoiningParty function, every time NumPlayer tries to find the amount of players inside the Idex.Party.Group it doesn't return the right amount of players that is actually in the table, it just returns 0. How do I fix this???

Here is part of the script:

local MapNames = {"Map1","Map2"}

local PlaceMapID = {
    ["Map1"] = {ID = 123246764},
    [2] = {ID = 123246764},
    [3] = {ID = 123246764}
    }



local PartyList = {}

O = 0
function OnPartyCreation(Player, Maps)
O = O + 1   
local Mapi = PartyList[MapNames]
local A,B = pcall(function()
    print(GetMapID(Maps))
    local Created 
    local CreatePartMap
    Created = false
    repeat 
    PartyList[#PartyList] = {
    Party = {

        Leader = Player;
        Group = {}

        },
    MapName = Maps  
    }
    wait()
    CreatePartMap = PartyList[#PartyList].Party
    Created = true
    until Created == true and CreatePartMap.Leader ~= nil
    return print("New party was created"), print(unpack(CreatePartMap.Group))
end)
print(A,B)
end

function OnJoiningParty(Player, Map)
    local MaxPlayers = Services.Players.MaxPlayers
    print("hi")
    repeat wait() until Player 
        for _,Idex in pairs(PartyList) do
            local Names = Idex.MapName
                print(5)
            if Map ==  Names then
                print(111)
    for NumPlayer = 0,#Idex.Party.Group do  
        print(6)
        if NumPlayer > MaxPlayers then
            print(7)
            warn("Party is full, "..NumPlayer .." < ".. MaxPlayers)
        else
    table.insert(Idex.Party.Group,Player.Name)
    print(unpack(Idex.Party.Group))
    SwitchTables(Lobby,InParty,Player.Name)
        print(unpack(InParty))
        print(unpack(Lobby))
    warn("Party is not full, "..NumPlayer .." > ".. MaxPlayers)
    print(Player.Name.." has joined the party")
        break
            end
            end
    end
        end
        end

game.ReplicatedStorage.GameFolder.Remotes.JoinParty.OnServerEvent:Connect(OnJoiningParty)

game.ReplicatedStorage.GameFolder.Remotes.CreateParty.OnServerInvoke = OnPartyCreation

Here is a more focused part of the problem inside the script:

function OnJoiningParty(Player, Map)
    local MaxPlayers = Services.Players.MaxPlayers
    print("hi")
    repeat wait() until Player 
        for _,Idex in pairs(PartyList) do
            local Names = Idex.MapName
                print(5)
            if Map ==  Names then
                print(111)
    for NumPlayer = 0,#Idex.Party.Group do  
        print(6)
        if NumPlayer > MaxPlayers then
            print(7)
            warn("Party is full, "..NumPlayer .." < ".. MaxPlayers)
        else
    table.insert(Idex.Party.Group,Player.Name)
    print(unpack(Idex.Party.Group))
    SwitchTables(Lobby,InParty,Player.Name)
        print(unpack(InParty))
        print(unpack(Lobby))
    warn("Party is not full, "..NumPlayer .." > ".. MaxPlayers)
    print(Player.Name.." has joined the party")
        break
            end
            end
    end
        end
        end

game.ReplicatedStorage.GameFolder.Remotes.JoinParty.OnServerEvent:Connect(OnJoiningParty)

Answer this question