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

How do I make this a game loop forever?

Hi I was making a game script, but the problem with the game script is when a player gets 5 points the game ends. Can you help me with making it a loop forever. Please?

local gameOver = false
if gameOver == false then
	for a = 1,1,1 do
		game.ReplicatedStorage.Cows:Clone().Parent = workspace
	end
	warn("running game")
	while true do

wait()
    for _, player in next, game.Players:GetPlayers() do

        if getScore(player, "Cow Clicks") >= highScore then

            gameOver = true
        end
    end

    if gameOver == true then
	game.Workspace.Cows:remove()
	
	warn("wins")
	wait(5)
		gameOver = false		
for i, player in ipairs(game.Players:GetChildren()) do
   if player.Character and player.Character:FindFirstChild("Torso") then
      player.Character:MoveTo(spawns[i])
	player.leaderstats["Cow Clicks"].Value = 0
	gameOver = false
end	
end
end
end
end

2 answers

✓ Accepted answer

You're making it way too complicated. Your code is executed from top to bottom -- it's sequential. Therefore to make A happen before B, all you literally need to do is write A before you write B! You don't need to do all these checks with a game over variable, you just need to code everything in the correct order.

I'm not gonna write a ton of code for you, but here's how I think you should structure it:

while true do
	--Intermission, will probably include a for loop with a count down.

	--Intermission is now over. Begin the round.

	--Wait until the round is over. Again, will most likely be a timer.

	--Round is now over. Tele players, delete maps, etc etc.

	--Now it goes back to Intermission at the top.
end

To be perfectly honest I think you should uh delete from line 1 to everything

Edit: Heres an explanation

You are making a game last forever. There is no need for a gameOver variable. Delete line 1.

Your for loop wants to end your awesome forever game. Delete lines 3-12.

YOUR IF STATEMENT WANTS TO CHECK IF THE GAMES OVER? THE GAMES NEVER OVER. Delete lines 13-18.

Why do we need to reset the scores and positions. Sounds suspiciously as if the GAMES GONNA BE OVER!! Delete lines 19-24.

Now you have an empty while loop. Delete line 26 and above.

1 comment

1
  • Explain. - No argument's good without evidence to support.

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