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

How could I close my while loop without it crashing?

Asked by 7 years ago
Edited 7 years ago

My while statement is completely skipped... The script instead goes to the area where I make a message on screen "Get Ready to Fight!" Why does this happen?

while game.ServerStorage.DoesArena1Have2Players.Value == 1 do 
        m = Instance.new("Message", workspace)
         m.Text = "Waiting for the CHALLENGER.."
            if game.ServerStorage.DoesArena1Have2Players.Value == 2
                then break
            end
 --- I want my loop to end here...  
            m:Destroy()







    m = Instance.new("Message", workspace)
    m.Text = "Get Ready to Fight!"
    wait(5)
    m:Destroy()

Full Code

debounce = false

script.Parent.Touched:connect(function(hit)
Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:findFirstChild("Humanoid") then
    if game.ServerStorage.DoesArena1Have2Players.Value == 2 then
     if debounce == true then 
        return
    end
    debounce = true
    m = Instance.new("Message", workspace)
    m.Text = "This ARENA has two PLAYERS fighting!"
    wait(2)
    m:Destroy()
    debounce = false

        return 
    elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then
        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1
    end



    if debounce == true then 
        return
    end
    debounce = true
    Char = hit.Parent
    Char.Torso.CFrame = CFrame.new(game.Workspace.tele.Position + Vector3.new(0, 5, 0))
    debounce = false


    while game.ServerStorage.DoesArena1Have2Players.Value == 1 do 
        m = Instance.new("Message", workspace)
         m.Text = "Waiting for the CHALLENGER.."
            if game.ServerStorage.DoesArena1Have2Players.Value == 2
                then
                m:Destroy()
                 break
            end







    m = Instance.new("Message", workspace)
    m.Text = "Get Ready to Fight!"
    wait(5)
    m:Destroy()


game.ReplicatedStorage["Sword"]:clone().Parent = Player2.Backpack

    end
    end
end)


0
Where is the ending to it? Meltdown81 309 — 7y
0
I pasted the entire thing Relampago1204 73 — 7y

1 answer

Log in to vote
-1
Answered by
brianush1 235 Moderation Voter
7 years ago

You just needed to move the end keyword

debounce = false

script.Parent.Touched:connect(function(hit)
Player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:findFirstChild("Humanoid") then
    if game.ServerStorage.DoesArena1Have2Players.Value == 2 then
     if debounce == true then 
        return
    end
    debounce = true
    m = Instance.new("Message", workspace)
    m.Text = "This ARENA has two PLAYERS fighting!"
    wait(2)
    m:Destroy()
    debounce = false

        return 
    elseif game.ServerStorage.DoesArena1Have2Players.Value <= 1 then
        game.ServerStorage.DoesArena1Have2Players.Value = game.ServerStorage.DoesArena1Have2Players.Value+1
    end



    if debounce == true then 
        return
    end
    debounce = true
    Char = hit.Parent
    Char.Torso.CFrame = CFrame.new(game.Workspace.tele.Position + Vector3.new(0, 5, 0))
    debounce = false


    while game.ServerStorage.DoesArena1Have2Players.Value == 1 do 
        m = Instance.new("Message", workspace)
         m.Text = "Waiting for the CHALLENGER.."
            if game.ServerStorage.DoesArena1Have2Players.Value == 2
                then
                m:Destroy()
                 break
            end
end
-- moved it here





    m = Instance.new("Message", workspace)
    m.Text = "Get Ready to Fight!"
    wait(5)
    m:Destroy()


game.ReplicatedStorage["Sword"]:clone().Parent = Player2.Backpack

    --this was here: end
    end
end)



Ad

Answer this question