Repeat untill not running

image
ok nvm its working but now if the minigame ends its still on the timer and its not doing loop
or am i supposed to place it somewhere else?

I do not know, try using a different loop.

does the same thing,
its hopeless :frowning:

if anyone knows the answer please tell me

Snipping this, no longer needed.

looks like it would work but there was an error

Workspace.Main:37: attempt to index number with ‘Position’

local players = game:GetService("Players")
local s = script:WaitForChild("Stat")
local rs = game:GetService("ReplicatedStorage")
local maps = rs:WaitForChild("Maps"):GetChildren()
local t = 0
local spawn1Folder = workspace:WaitForChild("Spawns")
local spawn2Folder = workspace:WaitForChild("Spawns2")
local spawns1 = spawn1Folder:GetChildren()
local spawns2 = spawn2Folder:GetChildren()
local ingameFolder = workspace:WaitForChild("Ingame")

local function doRound()
	local rand = math.random(1, #maps)
	local map = maps[rand]:Clone()
	map.Parent = workspace

	t = 15
	repeat
		t -= 1
		s.Value = "Intermission "..t
		task.wait(1)
	until t == 0

	s.Value = "Game Starting!"
	task.wait(1)

	s.Value = "We'll be playing "..map.Name
	task.wait(3)

	local players = players:GetPlayers()
	for _, player in ipairs(players) do
		local character = player.Character
		if character then
			local randomSpawn1 = math.random(1, #spawns1)
			local randomSpawn2 = math.random(1, #spawns2)
			local setSpawn1 = spawns1[randomSpawn1]
			local setSpawn2 = spawns2[randomSpawn2]
			if map.Name == "Obby" then
				character:MoveTo(setSpawn2.Position)
				character.Parent = ingameFolder
			elseif map.Name == "Mountain Over Flow!" then
				character:MoveTo(setSpawn2.Position)
				character.Parent = ingameFolder
			else
				character:MoveTo(setSpawn1.Position)
				character.Parent = ingameFolder
			end
		end
	end

	local roundLength = 120
	local canWin = true
	local roundType = ""

	if map:FindFirstChild("Obby") then
		roundType = "Obby"
		local endPart = map:WaitForChild("Endpart")
		endPart.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") and canWin then
				canWin = false
				s.Value = hit.Parent.Name.." has won!"
				local plr = players:GetPlayerFromCharacter(hit.Parent)
				if plr then
					local leaderstats = plr:WaitForChild("leaderstats")
					if leaderstats then
						local Wins = leaderstats:WaitForChild("Wins")
						local Points = leaderstats:WaitForChild("Points")
						if Wins and Points then
							Wins.Value += 1
							Points.Value += 10
						end
					end
				end
			end
		end)

	elseif map:FindFirstChild("Snowball") then
		roundType = "Snowball"
		local tool = map:FindFirstChildWhichIsA("Tool")
		local roundPlayers = ingameFolder:GetChildren()
		for _, player in ipairs(roundPlayers) do
			local toolClone = tool:Clone()
			toolClone.Parent = player
		end
		tool:Destroy()

	elseif map:FindFirstChild("Mountain Over Flow!") then
		roundType = "Mountain Over Flow!"
		local endPart = map:WaitForChid("Endpart")
		endPart.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") and canWin then
				canWin = false
				s.Value = hit.Parent.Name.." has won!"
				local plr = players:GetPlayerFromCharacter(hit.Parent)
				if plr then
					local leaderstats = plr:WaitForChild("leaderstats")
					if leaderstats then
						local Wins = leaderstats:WaitForChild("Wins")
						local Points = leaderstats:WaitForChild("Points")
						if Wins and Points then
							Wins.Value += 1
							Points.Value += 10
						end
					end
				end
			end
		end)
	end

	local roundPlayers = ingameFolder:GetChildren()
	repeat
		roundPlayers = ingameFolder:GetChildren()
		roundLength -= 1
		s.Value = "Time Left: "..roundLength
		task.wait(1)
	until roundLength == 0 or canWin == false or #roundPlayers == 0 or (#roundPlayers == 1 and roundType ==  "Snowball")

	if (#roundPlayers == 1 and roundType == "Snowball") and canWin then
		canWin = false
		local plr = roundPlayers[1]
		s.Value = plr.Name.. " has won!"
		if plr then
			local leaderstats = plr:WaitForChild("leaderstats")
			if leaderstats then
				local Wins = leaderstats:WaitForChild("Wins")
				local Points = leaderstats:WaitForChild("Points")
				if Wins and Points then
					Wins.Value += 1
					Points.Value += 10
				end
			end
		end
	end

	task.wait(5)
	map:Destroy()

	for _, player in ipairs(players) do
		player:LoadCharacter()
	end
end

task.wait(5)
doRound()

Typo on my end, excuse that.

1 Like

Another error

WaitForChid is not a valid member of Model "Workspace.Obby"