I need help with creating a gameloop

So I have a bomb tag game implemented where a random player obtains a bomb and when they tag someone that player gets said bomb, but once that bomb explodes, it should start again and again until there is 1 person remaining, which then it will loop waiting for 4 players to be on the in team and starting over again.

Here is my script:

local value = math.random(1, #game.Teams.In:GetPlayers())

for num, player in pairs(game.Teams.In:GetPlayers()) do
	local char = player.Character
	local val = math.random(1,18)
	
	game.ReplicatedStorage.RemoteEvents.CamType:FireClient(player, "Custom")
	
	game.ReplicatedStorage.RemoteEvents.StartGame:FireClient(player)

	for i, v in pairs(Map.Spawns:GetChildren()) do
		if i == val then
			char.HumanoidRootPart.CFrame = v.CFrame
			char.Humanoid.WalkSpeed = 0
		end
	end
end

game.ReplicatedStorage.RemoteEvents.TextLabel:FireAllClients("Choosing Gamemode...")

wait(4)

game.ReplicatedStorage.RemoteEvents.TextLabel:FireAllClients("Gamemode Chosen - Bomb Tag")

wait(3)

for i, v in pairs(game.Teams.In:GetPlayers()) do
	
	local char = v.Character

	char.Humanoid.WalkSpeed = 30
	
	if value == i then

		bomber = v.Character
		
		game.ReplicatedStorage.RemoteEvents.TextLabel:FireAllClients(bomber.Name.." Is The Bomber!")

		local bomb = game.ReplicatedStorage.Bomb:Clone()
		bomb.Parent = workspace
		--bomb.Position = v.Character.UpperTorso.Position + Vector3.new(0, -7, 0)

		local weld = Instance.new("Weld")
		weld.Name = "BombWeld"
		weld.Part0 = bomber.UpperTorso
		weld.Part1 = bomb
		weld.C0 = CFrame.new(0,0.3,-2.7)
		weld.C1 *= CFrame.Angles(math.pi/2,0,0)
		--weld.C0 = CFrame.new(v.Character.UpperTorso.Position, bomb.Position)

		workspace.Effects.Anchored = false
		workspace.Effects.Weld.Part1 = bomb

		weld.Parent = bomb


		local animation = Instance.new("Animation")  -- Create Animation object
		animation.AnimationId = "rbxassetid://13245017538"  -- Set the animation ID
		local animationTrack = bomber.Humanoid:LoadAnimation(animation)  -- Load the animation
		animationTrack:Play()  -- Play the animation

		bomb.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent ~= bomber then
					animation:Destroy()

					bomber = hit.Parent
					weld.Part0 = bomber.UpperTorso

					local animation = Instance.new("Animation")  -- Create Animation object
					animation.AnimationId = "rbxassetid://13245017538"  -- Set the animation ID
					local animationTrack = bomber.Humanoid:LoadAnimation(animation)  -- Load the animation
					animationTrack:Play()

				end
			end
		end)

		local val = 1
		local val2 = math.random(-1.3,-0.9)

		while wait(val) do
			bomb.Sound:Play()
			bomb.PointLight.Enabled = true
			bomb.Highlight.Enabled = true
			wait(val)
			val = val - 0.05
			bomb.PointLight.Enabled = false
			bomb.Highlight.Enabled = false
			if val < val2 then

				for i, v in pairs(workspace.Effects:GetChildren()) do
					if v:IsA("ParticleEmitter") then
						v:Emit(50)
					end
				end
				workspace.Sound2:Play()
			bomber.Humanoid:TakeDamage(bomber.Humanoid.Health)
			bomb:Destroy()
            local playerbomber = game.Players:GetPlayerFromCharacter(bomber)
            playerbomber.Team = game.Teams.Out

				break
			end
		end

	end
end