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

This code keeps looping, i think i may be using the 'for' loop wrong?

Asked by 7 years ago
local plr = game.Players:GetPlayers()
    for i,v in pairs (plr)do 
        table.insert(_G.Playing,v) -- Inserting Player into table
        print(v.Name..' is _G.Playing')
    end
    for i,v in pairs (_G.Playing)do 
        local char = v.Character
        local human = char:WaitForChild('Humanoid') 
        if char and human then  
            workspace.Values.Status.Value = 'The next gamemode is Classic!'
            wait(3)
            for i,chars in pairs (_G.Playing) do
            teleport.telePlayers(chars,workspace:WaitForChild'Spawn') -- Teleport to arena 
            end
            status.Value = 'Simple, everyone gets a basic sword and fights to be the last one alive! Get Ready!'
            wait(8) 
            status.Value = 'Giving every player their sword...'
                    for i,back in pairs (_G.Playing) do
            giveWeapon.giveWeaponToPlayers(back,game:GetService('ReplicatedStorage').Tools.Sword)
                    end
        end
        wait(3)
    end
    status.Value = 'Kill every player and be the last one standing to win!'

Yes, i have posted this a while ago, but no one helped it so i was hoping someone can help me with this, basically what happens is just keeps doing this code over and over again and doesnt allow the rest of the script to execute. Any answers with explanations are happily requested!

1 answer

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

moved the end you had on line 14, it should work now

local plr = game.Players:GetPlayers()
    for i,v in pairs (plr)do 
        table.insert(_G.Playing,v) -- Inserting Player into table
        print(v.Name..' is _G.Playing')
    end
    for i,v in pairs (_G.Playing)do 
        local char = v.Character
        local human = char:WaitForChild('Humanoid') 
        if char and human then  
            workspace.Values.Status.Value = 'The next gamemode is Classic!'
            wait(3)
            for i,chars in pairs (_G.Playing) do
            teleport.telePlayers(chars,workspace:WaitForChild'Spawn') -- Teleport to arena 

            status.Value = 'Simple, everyone gets a basic sword and fights to be the last one alive! Get Ready!'
            wait(8) 
            status.Value = 'Giving every player their sword...'
                    for i,back in pairs (_G.Playing) do
            giveWeapon.giveWeaponToPlayers(back,game:GetService('ReplicatedStorage').Tools.Sword)
end
                    end
        end
        wait(3)
    end
    status.Value = 'Kill every player and be the last one standing to win!'
0
it still does it, this just made it loop even faster and everything was going crazy.. sentry3 6 — 7y
0
is this a local script or server script? and where is the script located at? im gonna try to test it User#12356 0 — 7y
Ad

Answer this question