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

When someone leaves and quits my game it breaks my repeat loop causing it to bug out?

Asked by 4 years ago
Edited 4 years ago

So i have a zombie game with rounds
When someone quits the game it bugs the round causing it to stop my repeat loop of zombie rounds than it never runs again freezing the timer and not running?

repeat wait()

        game.Players.PlayerRemoving:Connect(function(player)

            collectionservice:AddTag(player.Character, "Dead")

        end)

        for x, player in pairs(plrs) do
            if player then
                character = player.Character
                collectionservice:AddTag(player.Character, "Alive")

                if not character then
                    -- left the game
                    table.remove(plrs,x)
                    player.ingame.Value = false 
                    collectionservice:AddTag(player.Character, "Dead")  
                else
                    if character:FindFirstChild("GameTag") then
                        -- They are still alive
                        print(player.Name.." is still in the game!")
                        player.ingame.Value = true
                        collectionservice:AddTag(player.Character, "Alive")
                    else
                        -- They are dead
                        table.remove(plrs,x)
                        player.ingame.Value = false
                        collectionservice:AddTag(player.Character, "Dead")
                    end
                end
            else

            table.remove(plrs,x)
            print(player.Name.." has been removed!")
            end
        end

    for i = GameLength,0,-1 do
        if gameInProgress.Value == false then
        Status.Value = "GAME OVER, Starting New Game"
        break
    end

        Status.Value = ""..i.." seconds ramaining, "


        if zombiesAlive.Value <= 5 then
            zombieCount.Value = 25 
            zombiesAlive.Value = 25
        end

        wait()
        if #collectionservice:GetTagged("Alive") == 0 then


    name = player.Name
    check = game.Workspace:FindFirstChild(name)
    if check then
        checkHumanoid = check:findFirstChild("Humanoid")
        if checkHumanoid then
            for i, player in pairs(game.Players:GetPlayers()) do
                ingamez = player:FindFirstChild("ingamez")
                if ingamez then
                    if ingamez.Value == false then
            -- Teleport them
            player.Character:MoveTo(AvailableSpawnPoints[i].Position)
            collectionservice:AddTag(player.Character, "Alive")
            player.ingamez.Value = true
            local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

    until gameInProgress.Value == false and #collectionservice:GetTagged("Alive") == 0 

    wait()
    print("End of game")

    for i, player in pairs(game.Players:GetPlayers()) do
        character = player.Character

        player:LoadCharacter()

        if not character then
            -- ignore tehm
        else 
            if character:FindFirstChild("GameTag") then
                character.GameTag:Destroy()
            end

            for _, tool in pairs(player.Backpack:GetChildren()) do
                if tool:FindFirstChild("Price") then
                    tool:Destroy()
                end
            end

            for _, tool in pairs(character:GetChildren()) do
                if tool:FindFirstChild("Price") then
                    tool:Destroy()
                end
            end
        end
        wait (2)
        player:LoadCharacter()
    end

    ClonedMap:Destroy()

    Status.Value = "Game Ended"
    wait(2)
0
You could just move the things that have nothing to do in the repeat above the repeat function. save_database 15 — 4y
1
Can you please narrow your code down to where the problem is occurring? Not many people want to read through a large wall of code pidgey 548 — 4y
0
defintly not, i skipped after about 10 lines when i realised it was huge Gameplayer365247v2 1055 — 4y

Answer this question