My Code Doesn't Repeat, at a Certain Part?
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
1 | 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
01 | local playersFighting = { } |
04 | workspace.PvpSystem.Part.Touched:Connect( function (hit) |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 | if #playersFighting < 3 then |
07 | if not table.find(playersFighting, hit.Parent) then |
08 | table.insert(playersFighting, hit.Parent) |
09 | print ( "Added Player: " ..hit.Parent.Name.. " to the Table!" ) |
11 | print ( "You are already in the table" ) |
14 | print ( "There are already 2 members" ) |
19 | repeat wait() until #playersFighting = = 2 do |
20 | playersFighting [ 1 ] .HumanoidRootPart.Position = workspace.PvpSystem.player 1 TP.Position + Vector 3. new( 0 , 6 , 0 ) |
21 | playersFighting [ 2 ] .HumanoidRootPart.Position = workspace.PvpSystem.player 2 TP.Position + Vector 3. new( 0 , 6 , 0 ) |
23 | for i, v in pairs (playersFighting) do |
24 | local theSword = game.ServerStorage:WaitForChild( "ClassicSword" ):Clone() |
29 | v.Humanoid.Died:Connect( function (player) |
30 | table.remove(playersFighting, i) |
32 | print ( "The Winner is: " ..v.Name) |
34 | table.remove(playersFighting, i) |