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

script wont continue after for i,v in pairs loop?

so im making minigames and i want a script that chooses a minigame disable after players are teleported to the game. so the problem is that the script ends when the loop ends and the script doesnt get disabled. heres the script i dont know if its gonna help but ima just put it

while true do
	wait(25)
	local games = game.ServerStorage.Minigames:GetChildren()
	if #game.Players:GetChildren() >= 2 then
		game.StarterGui.MorePlayers.TextLabel.Visible = false
		local choosengame = games[math.random(1,#games)]
		local gameclone = choosengame:Clone()
		gameclone.Parent = game.Workspace.CurrentGame
		local spawns = gameclone:WaitForChild("Spawns"):GetChildren()
		wait(3)
		for i,v in pairs(game.Players:GetChildren()) do
			v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)
			v.Team = game.Teams["In-Game"]
			local scriptclone = script.ChangeTeamWhenDied:Clone()
			scriptclone.Parent = v
			scriptclone.Disabled = false
		end
		script.Disabled = true
	end
end

any help appreciated

2 comments

0

Why is this even wrapped in a while loop if you want the script to stop executing after it finishes the for loop?

0

so the intermission starts again when a game is finished?

1 answer

Instead wrap all that into a function, and then call it using BindableEvents when you are ready for another round to begin. Like this:

function chooseRound()
	--for in pairs loop
end

BindableEvent.Event:Connect(chooseRound)

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