Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

My Code Doesn't Repeat, at a Certain Part?

Asked by
Borrahh 265 Moderation Voter
4 years ago

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

1repeat 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

01local playersFighting = {}
02 
03 
04workspace.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!")
10            else
11                print("You are already in the table")
12            end
13        else
14            print("There are already 2 members")
15        end
View all 37 lines...

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Well that line is not written correctly...I do not think you can put "repeat until...do." If you're meaning to run the code when there are 2 players fighting, wouldn't it better to use "while true do"?? Or did you mean to use a "repeat until" loop?

01while #playersFighting == 2 do
02    wait()
03    playersFighting[1].HumanoidRootPart.Position = workspace.PvpSystem.player1TP.Position + Vector3.new(0, 6, 0)
04    playersFighting[2].HumanoidRootPart.Position = workspace.PvpSystem.player2TP.Position + Vector3.new(0, 6, 0)
05    -- game here
06    for i, v in pairs(playersFighting) do
07        local theSword = game.ServerStorage:WaitForChild("ClassicSword"):Clone()
08        theSword.Parent = v
09 
10 
11 
12        v.Humanoid.Died:Connect(function(player)
13            table.remove(playersFighting, i)
14            --Reward
15            print("The Winner is: "..v.Name)
16 
17            table.remove(playersFighting, i)
18        end)
19    end
20end
Ad

Answer this question