Maybe it’s because you are trying to play animations that are already playing. So you can add this part at the start of the while (DefendingPlayer.Backpack.Data.CurrentLives.Value > 0) do loop:
for _, anim in AttackingPlayer.Character.Humanoid.Animator:GetPlayingAnimationTracks() do
if anim.Animation.Parent == game.ReplicatedStorage.Animations then
anim:Stop()
end
end
for _, anim in DefendingPlayer.Character.Humanoid.Animator:GetPlayingAnimationTracks() do
if anim.Animation.Parent == game.ReplicatedStorage.Animations then
anim:Stop()
end
end
This will stop all current attack/defend animations.
for i, v in pairs(Rows) do
PlayedAnimation = true
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.4)
end
To here:
if AttackerChose == DefenderChose then
print("Defender Loses a life, Total:", DefendingPlayer.Backpack.Data.CurrentLives.Value)
DefendingPlayer.Backpack.Data.CurrentLives.Value -= 1
print(Rows)
table.insert(Rows, DefendingPlayer.Backpack.Data.ChosenMove.Value)
for i, v in pairs(Rows) do
PlayedAnimation = true
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.4)
end
if #Rows == 3 then
DefendingPlayer.Backpack.Data.CurrentLives.Value = 0
end
game.ReplicatedStorage.Client.HideButton:FireClient(AttackingPlayer, "Attack", AttackerChose)
game.ReplicatedStorage.Client.HideButton:FireClient(DefendingPlayer, "Defend", DefenderChose)
else
-- Right here
Rows = {}
Switch = true
end
while (DefendingPlayer.Backpack.Data.CurrentLives.Value > 0) do
if Switch then
local TempPlayer = AttackingPlayer
AttackingPlayer = DefendingPlayer
DefendingPlayer = TempPlayer
Switch = false
end
AttackingPlayer.Backpack.Data.State.Value = "Attack"
DefendingPlayer.Backpack.Data.State.Value = "Defend"
repeat task.wait() until (AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= "")
local AttackerChose = AttackingPlayer.Backpack.Data.ChosenMove.Value
local DefenderChose = DefendingPlayer.Backpack.Data.ChosenMove.Value
print("Attacker Chose", AttackerChose)
print("Defender Chose", DefenderChose)
local PlayedAnimation = false
if AttackerChose == DefenderChose then
print("Defender Loses a life, Total:", DefendingPlayer.Backpack.Data.CurrentLives.Value)
DefendingPlayer.Backpack.Data.CurrentLives.Value -= 1
print(Rows)
table.insert(Rows, DefendingPlayer.Backpack.Data.ChosenMove.Value)
for i, v in pairs(Rows) do
PlayedAnimation = true
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.5)
end
if #Rows == 3 then
DefendingPlayer.Backpack.Data.CurrentLives.Value = 0
end
game.ReplicatedStorage.Client.HideButton:FireClient(AttackingPlayer, "Attack", AttackerChose)
game.ReplicatedStorage.Client.HideButton:FireClient(DefendingPlayer, "Defend", DefenderChose)
else
for i, v in pairs(Rows) do
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.5)
end
Rows = {}
Switch = true
end
if not PlayedAnimation then
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..AttackingPlayer.Backpack.Data.ChosenMove.Value]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..DefendingPlayer.Backpack.Data.ChosenMove.Value]):Play()
end
wait(1)
AttackingPlayer.Backpack.Data.ChosenMove.Value = ""
DefendingPlayer.Backpack.Data.ChosenMove.Value = ""
end
DefendingPlayer.Character.Humanoid.Health = 0
AttackingPlayer.Character.HumanoidRootPart.Anchored = false
AttackingPlayer.Backpack.Data.State.Value = ""
DefendingPlayer.Backpack.Data.State.Value = ""
AttackingPlayer.Backpack.Data.Ring.Value = nil
DefendingPlayer.Backpack.Data.Ring.Value = nil
Attacker.Value = nil
Defender.Value = nil
Billboard.TextLabel.Text = Occupants.. "/2"
for i, v in pairs(Corners) do
v.Occupant.Value = nil
end
Occupants = 0
local Player1 = Corners[1].Occupant.Value
local Player2 = Corners[2].Occupant.Value
-- Update Player1's UI
Defender.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
Defender.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
-- Update Player2's UI
Attacker.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
Attacker.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
end
It has to be at the end of the while loop, like this:
while (DefendingPlayer.Backpack.Data.CurrentLives.Value > 0) do
if Switch then
local TempPlayer = AttackingPlayer
AttackingPlayer = DefendingPlayer
DefendingPlayer = TempPlayer
Switch = false
end
AttackingPlayer.Backpack.Data.State.Value = "Attack"
DefendingPlayer.Backpack.Data.State.Value = "Defend"
repeat task.wait() until (AttackingPlayer.Backpack.Data.ChosenMove.Value ~= "") and (DefendingPlayer.Backpack.Data.ChosenMove.Value ~= "")
local AttackerChose = AttackingPlayer.Backpack.Data.ChosenMove.Value
local DefenderChose = DefendingPlayer.Backpack.Data.ChosenMove.Value
print("Attacker Chose", AttackerChose)
print("Defender Chose", DefenderChose)
local PlayedAnimation = false
if AttackerChose == DefenderChose then
print("Defender Loses a life, Total:", DefendingPlayer.Backpack.Data.CurrentLives.Value)
DefendingPlayer.Backpack.Data.CurrentLives.Value -= 1
print(Rows)
table.insert(Rows, DefendingPlayer.Backpack.Data.ChosenMove.Value)
for i, v in pairs(Rows) do
PlayedAnimation = true
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.5)
end
if #Rows == 3 then
DefendingPlayer.Backpack.Data.CurrentLives.Value = 0
end
game.ReplicatedStorage.Client.HideButton:FireClient(AttackingPlayer, "Attack", AttackerChose)
game.ReplicatedStorage.Client.HideButton:FireClient(DefendingPlayer, "Defend", DefenderChose)
else
for i, v in pairs(Rows) do
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..v]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..v]):Play()
wait(0.5)
end
Rows = {}
Switch = true
end
if not PlayedAnimation then
AttackingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Attack"..AttackingPlayer.Backpack.Data.ChosenMove.Value]):Play()
DefendingPlayer.Character.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations["Defend"..DefendingPlayer.Backpack.Data.ChosenMove.Value]):Play()
end
wait(1)
AttackingPlayer.Backpack.Data.ChosenMove.Value = ""
DefendingPlayer.Backpack.Data.ChosenMove.Value = ""
local Player1 = Corners[1].Occupant.Value
local Player2 = Corners[2].Occupant.Value
-- Update Player1's UI
Defender.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
Defender.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
-- Update Player2's UI
Attacker.PlayerGui.ShadowBoxing.Player1.Lives.Text = Player1.Backpack.Data.CurrentLives.Value
Attacker.PlayerGui.ShadowBoxing.Player2.Lives.Text = Player2.Backpack.Data.CurrentLives.Value
end