Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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!'

2 comments

0

it still does it, this just made it loop even faster and everything was going crazy..

0

is this a local script or server script? and where is the script located at? im gonna try to test it

This discussion is preserved as it was. New answers, comments, and votes are closed.