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)
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)