The Idea is, when 2 players touch a part, they enter the table, Get teleported to the Parts, and then have a sword fight, which works fine for the first time. When they try to duel again, the code from
repeat wait() until #playersFighting == 2 do
to the end, doesn't work, I don't get any error, They don't get any swords, or get telepored, anyone knows why
local playersFighting = {}
workspace.PvpSystem.Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if #playersFighting < 3 then
if not table.find(playersFighting, hit.Parent) then
table.insert(playersFighting, hit.Parent)
print("Added Player: "..hit.Parent.Name.." to the Table!")
else
print("You are already in the table")
end
else
print("There are already 2 members")
end
end
end)
repeat wait() until #playersFighting == 2 do
playersFighting[1].HumanoidRootPart.Position = workspace.PvpSystem.player1TP.Position + Vector3.new(0, 6, 0)
playersFighting[2].HumanoidRootPart.Position = workspace.PvpSystem.player2TP.Position + Vector3.new(0, 6, 0)
-- game here
for i, v in pairs(playersFighting) do
local theSword = game.ServerStorage:WaitForChild("ClassicSword"):Clone()
theSword.Parent = v
v.Humanoid.Died:Connect(function(player)
table.remove(playersFighting, i)
--Reward
print("The Winner is: "..v.Name)
table.remove(playersFighting, i)
end)
end
end
