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

[SOLVED] Why does this script's While True do stop working?

Asked by 4 years ago
Edited 4 years ago

The while true do stops working after a player wins a duel and because of that it doesn't start a new match. Sometimes it also doesn't even start a match and stops printing.

local isMatchGoing = false

local players = game:GetService("Players")

    while true do
            wait(1)
            print(isMatchGoing)
        if not isMatchGoing and #players:GetPlayers() > 1 then
        local random1 = math.random(1,#players:GetPlayers())
        local random2 = math.random(1,#players:GetPlayers())
        if random1 == random2 then return end

            local plr1 = players:GetPlayers()[random1]
            local plr2 = players:GetPlayers()[random2]

            if plr1 and plr2 then
                isMatchGoing = true
                local chr1 = plr1.Character or plr1.CharacterAdded:Wait()
                local chr2 = plr2.Character or plr2.CharacterAdded:Wait()

                chr1.HumanoidRootPart.CFrame = workspace.start1.CFrame
                chr2.HumanoidRootPart.CFrame = workspace.start2.CFrame

                local died

                died = chr1.Humanoid.Died:Connect(function()
                    if isMatchGoing then
                        plr2.leaderstats.Wins.Value = plr2.leaderstats.Wins.Value + 1
                        plr2:LoadCharacter()
                    end
                    isMatchGoing = false
                    died:Disconnect()
                end)

                local died2

                died2 = chr2.Humanoid.Died:Connect(function()
                    if isMatchGoing then
                        plr1.leaderstats.Wins.Value = plr1.leaderstats.Wins.Value + 1
                        plr1:LoadCharacter()
                    end
                    isMatchGoing = false
                    died2:Disconnect()
                end)
            end
        end
    end
0
Try disconnecting both died and died2 in each connections above, see if it works! Afterl1ght 321 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I had a return in the loop

Ad

Answer this question