How do i go to the next item in for loop?

			for _,plr in Players do
				game.Players[plr].Chatted:Connect(function(Message)
					if Message == "Hello world" then
						print("Right")
						-- Something here make the for loop goes to the nex item
					else
						print("Wrong")
					end
				end)
				wait(10)
				
			end
		end

This is where i need it thank you

2 Likes

If that’s what I’m thinking, then you need to use continue (it jumps to the next element immediately)

if Message == "Hello world" then
	print("Right")
	continue -- Something here make the for loop goes to the nex item
else
	print("Wrong")
end
2 Likes

it tell me

continue statement must be inside a loop

Is this code in a loop? Can you post more code.

1 Like
		for _,plr in Players do
			game.Players[plr].Chatted:Connect(function(Message)
				if Message == "Hello world" then
					print("Right")
					-- Something here make the for loop goes to the nex item
				else
					print("Wrong")
				end
			end)
			wait(10)
			
		end
	end

Can you explain exactly what do you want to achieve? Do you want to stop the loop if the message is “Hello World”?

1 Like

This code won’t work because on new message you are calling a new function which is not in the loop.

1 Like

i want it to go to the next item in the table

The loop will automatically continue. I’m not sure what do you exactly mean.

1 Like

it countinute after 10 seconds with wait()

So you don’t want the waiting period to affect it?

1 Like

every ten seconds it go to the next item
but if the player message “Hello world” it skip that time go to the next item

try it

for _,plr in Players do
	local skip
	game.Players[plr].Chatted:Connect(function(Message)
		if Message == "Hello world" then
			print("Right")
			skip=true -- Something here make the for loop goes to the nex item
		else
			print("Wrong")
		end
	end)
	local st=tick()
	repeat
		task.wait()
	until tick()-st>=10 or skip
end
1 Like

its now working thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.