I have a 1v1 script that works fine to a point, after a player has died once, it removes the other players tools and sets both players back to the correct position but that only works once, I would like it to work an infinite number of times, please help me by telling me what I am doing wrong. The following code is only the necessary parts, everything here is the main part, all the little parts work fine.
local function GameEnd(plrWon,plrLost,tied,forceStopped)
for i,v in next,CurrentGladiators do CurrentGladiators[i] = nil end
if forceStopped then
SetAnnouncer(tostring(plrWon).." has left the game")
wait(6)
SetPlayerImages()
SetAnnouncer("No match")
elseif plrWon and tied == false then
SetAnnouncer(plrWon.Name.." has won over "..plrLost.Name)
IncrementScore(plrWon,1)
wait(6)
SetPlayerImages()
SetAnnouncer("No match")
elseif tied == true then
SetAnnouncer(plrWon.Name.." was tied with "..plrLost.Name)
wait(6)
SetPlayerImages()
SetAnnouncer("No match")
else
SetAnnouncer("Time ran out")
if plrWon and plrWon.Character then
Teleport(plrWon,Return)
end
if plrLost and plrLost.Character then
Teleport(plrLost,Return)
end
wait(6)
SetPlayerImages()
SetAnnouncer("No match")
end
end
local function DeclareVictor(plrWon,plrLost)
--print(plrWon.Name.." won")
if plrWon == plr1 then
Plr1kills = Plr1kills + 1
wait(4)
Teleport(plrWon,Spawn1)
Teleport(plrLost,Spawn2)
else if plrWon == plr2 then
Plr2kills = Plr2kills + 1
wait(4)
Teleport(plrWon,Spawn2)
Teleport(plrLost,Spawn1)
plrWon.Character:FindFirstChild("Humanoid"):UnequipTools()
RemoveTools(plrWon)
game.ReplicatedStorage.MatchTools2.ClassicSword:Clone().Parent = game.Players:FindFirstChild(plr1.Name).Backpack
game.ReplicatedStorage.MatchTools2.ClassicSword:Clone().Parent = game.Players:FindFirstChild(plr2.Name).Backpack
GameInProgress,GameEnding = true,false
end
end
end
local function DeclareTie(plr1,plr2)
wait(4)
Teleport(plr1,Spawn1)
Teleport(plr2,Spawn2)
plr1.Character:FindFirstChild("Humanoid"):UnequipTools()
plr2.Character:FindFirstChild("Humanoid"):UnequipTools()
RemoveTools(plr1)
RemoveTools(plr2)
game.ReplicatedStorage.MatchTools2.ClassicSword:Clone().Parent = game.Players:FindFirstChild(plr1.Name).Backpack
game.ReplicatedStorage.MatchTools2.ClassicSword:Clone().Parent = game.Players:FindFirstChild(plr2.Name).Backpack
GameInProgress,GameEnding = false,false
end
local function OnGladiatorDied(plr)
--print(plr.Name.." died")
if not GameEnding then
GameEnding = false
local victor,tied = GetOpposingGlad(plr),false
wait(3)
local victorHum = victor.Character:WaitForChild("Humanoid")
if victorHum.Health <= 0 then tied = true end
if tied == false then
DeclareVictor(victor,plr)
if victor == plr1 then
Plr1kills = Plr1kills + 1
end
if victor == plr2 then
Plr2kills = Plr2kills + 1
end
else
DeclareTie(plr,victor)
end
end
end
local function SpawnPlayer(plr,part)
local hum = plr.Character and plr.Character:WaitForChild("Humanoid")
local weaponCache = {}
WeaponCache[plr] = weaponCache
for i,v in next,plr:WaitForChild("Backpack"):GetChildren() do v.Parent = nil weaponCache[#weaponCache+1] = v end
for i,v in next,Tools do v:Clone().Parent = plr:FindFirstChild("Backpack") end
Teleport(plr,part)
coroutine.wrap(function()
hum.Died:wait()
if (function() for i,v in next,CurrentGladiators do if v == plr then return true end end return false end)() then
OnGladiatorDied(plr)
end
end)()
end
local function StartGame(plr1,plr2)
SetPlayerImages(plr1,plr2)
SetAnnouncer (plr1.Name.." vs "..plr2.Name)
coroutine.wrap(function()
repeat wait() until GameEnding == true
end)()
coroutine.wrap(function()
repeat wait() until plr1.Parent ~= Players or plr2.Parent ~= Players or GameInProgress == false
if GameInProgress == true then
GameEnding = true
local leftPlr = plr1.Parent ~= Players and plr1 or plr2
local remainingPlr = plr1 == leftPlr and plr2 or plr1
Teleport(remainingPlr,Return)
if remainingPlr.Character:FindFirstChild("Humanoid") then
remainingPlr.Character.Humanoid:UnequipTools()
remainingPlr.Character.Humanoid.Health=100
end
RemoveTools(remainingPlr)
GameEnd(leftPlr,nil,false,true)
GameInProgress,GameEnding = false,false
end
end)()
if math.random(0,1) == 1 then
SpawnPlayer(plr1,Spawn1)
SpawnPlayer(plr2,Spawn2)
else
SpawnPlayer(plr2,Spawn1)
SpawnPlayer(plr1,Spawn2)
end
end
local function Check()
--print("Checking")
print(PendingPlayers.len)
print(#CurrentGladiators)
print(GameInProgress)
if PendingPlayers.len == 2 and #CurrentGladiators < 2 and GameInProgress == false then
GameInProgress = true
for i,v in next,PendingPlayers do CurrentGladiators[#CurrentGladiators+1] = v end
plr1,plr2 = unpack(CurrentGladiators)
if plr1 ~= plr2 then
StartGame(plr1,plr2)
end
end
end
