function ChooseDuelers() repeat wait() until game.Players.NumPlayers >=2 for i = 20, 0, -1 do script.Lobby:Play() h = Instance.new("Hint",workspace) h.Text = "Round starting in: " ..i wait(1) h:Destroy() end local Players=Game.Players:GetPlayers() local Chosen1, Chosen2 = math.random(1, #Players), 0 repeat Chosen2 = math.random(1, #Players) until Chosen2 ~= Chosen1 m = Instance.new("Message",workspace) m.Text = Players[Chosen1].Name.. " and " ..Players[Chosen2].Name.. " have been chosen!" wait(3) Players[Chosen1].Character:MoveTo(Vector3.new(-82.5, 0.59, 19)) Players[Chosen2].Character:MoveTo(Vector3.new(-82.5, 0.59, -25)) m.Text = "Duelers teleported, starting round." wait(3) m:Destroy() local chosen1 = game.Lighting.Chosen1:clone() chosen1.Parent = Players[Chosen1].Backpack local chosen2 = game.Lighting.Chosen2:clone() chosen2.Parent = Players[Chosen2].Backpack Players[Chosen1].Character.Humanoid.WalkSpeed = 0 Players[Chosen2].Character.Humanoid.WalkSpeed = 0 for i = 3, 0, -1 do m.Text = "Round starting in: " ..i wait(1) end for i = 30, 0, -1 do script.Lobby:Stop() script.Battle:Play() Players[Chosen1].Character.Humanoid.WalkSpeed = 16 Players[Chosen2].Character.Humanoid.WalkSpeed = 16 h = Instance.new("Hint",workspace) h.Text = "New round in: " ..i wait(1) if Players[Chosen1].Character.Humanoid.Health == 0 then h:Destroy() m = Instance.new("Message",workspace) m.Text = Players[Chosen2].Name.." won!" wait(3) m:Destroy() Players[Chosen2].Character:MoveTo(Vector3.new(-59.5, 1.79, -3)) script.Battle:Stop() end if Players[Chosen2].Character.Humanoid.Health == 0 then h:Destroy() m = Instance.new("Message",workspace) m.Text = Players[Chosen1].Name.." won!" wait(3) m:Destroy() Players[Chosen1].Character:MoveTo(Vector3.new(-59.5, 1.79, -3)) script.Battle:Stop() end end end ChooseDuelers()
Whenever a player dies, the game continues to play. What did I do wrong?
Checking if player died is located on line "39-47" and "48-56"
Use the died event. I think this should work. this is lines 39-56 (Inclusive)
Players[Chosen1].Character.Died:connect(function() h:Destroy() m = Instance.new("Message",workspace) m.Text = Players[Chosen2].Name.." won!" wait(3) m:Destroy() Players[Chosen2].Character:MoveTo(Vector3.new(-59.5, 1.79, -3)) script.Battle:Stop() end) Players[Chosen2].Character.Died:connect(function() h:Destroy() m = Instance.new("Message",workspace) m.Text = Players[Chosen1].Name.." won!" wait(3) m:Destroy() Players[Chosen1].Character:MoveTo(Vector3.new(-59.5, 1.79, -3)) script.Battle:Stop() end)